PDA

View Full Version : Networking



Keichioor
September 21st, 2010, 01:09 PM
Hello,
I am have question and any can discussion(if you have desire ;)) about how to network Flash(ActionScript 3) MovieClip ? something like:
I am have in Flash AS3 client Circle(MovieClip) and this Circle can move with Keyboard(UP,DOWN,LEFT,RIGHT) and how to make Multi-Circle(Multi-Player) Is incomprehensible to me now how. :rocker: ( Something like: http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/example-real-time-interpolated )

I am beginner in programming, but i am programming minimum in ActionScript 3, Python and Java.
I am minimum know how to which Flash/ActionScript 3 connect to Python/Java socket and minimum know how to send and receive Text(Chat program)

Please don't recommend SmartFoxServer, ElectroServer this project's is not open source. ;)

Thanks! I am very sorry for my English language(not my country base Language)

bluemagica
September 21st, 2010, 02:52 PM
Well there were a flash-java tutorial somewhere, just google it.....also this site has a outdated php socket server tutorial, which should atleast help you clear up the concepts of networking. Adobe has also released its own P2P communication server for flash player 10.1 called stratus, and I have a chat example with it on my blog, which you can see to understand the basics.

Keichioor
September 21st, 2010, 03:10 PM
Hello, bluemagica,
Yes i am searching on Google AS3/Java, AS3/Python tutorial's, but only find about how to create AS3/Java chat and low AS3/Python chat tutorial. :)
And hard think how to with MovieClips, but i am trying learn other programming language codes/examples and think how to make this. ;)
Thanks you for sharing you chat code and on you blog is really good stuff(i am go to learn more about Stratus :) )

bluemagica
September 21st, 2010, 03:26 PM
I plan on making a full multiplayer tutorial with stratus once it's out of the beta..... anyway, if you know how to make a chat, then that is all you really need to know. Networking is nothing but transaction of data. But what actually matters most is how you process and handle that data, outside the network layer. There are several architectures like spider-web or leaf-node architectures.

But if we are to skip the technical jargons and get in to how you should do things in flash, then this just means,
1) When a client starts, it will create one ball for itself with keyboard controls. Contact server for total number of player's and their ball coordinates, and then create that many ball instances as per the data received from server.
2) Clients send update messages to server(same as chat), in your case X and Y of the ball.
3) Server receives the message, does any processing required, like if you are colliding with another player's balls( don't read it in a weird way). and broadcasts the result to all clients connected to it.
4) All clients update their individual ball instances as per the data received from the server.

Keichioor
September 23rd, 2010, 07:24 AM
Hello again,
I am find on this forum Spark_BR AS2/Java example and start using Spark_BR Java server. ( http://www.kirupa.com/forum/showthread.php?t=327381&page=2 ) and thanks Voetsjoeba for one post example AS3/Java chat. :)
And i am have new problem, I am create MovieClip with name player and this "player" can walk with UP,DOWN,LEFT,RIGHT and i am send to player.x/player.y and if i am click button "Send" i am get player.x/player.y from Server, but my MovieClip(player) don't move on other Client's only on this client move where i am move player with keyboard and not multiplayer.
What i am doing wrong ?
Screenshot(On this screenshot i am move player DOWN(On: Flash_AS3_Client) and click Send and send player.x/player.y to other Client's and i am send message on chat "Movement" :):

http://img59.imageshack.us/img59/2151/screenshotguy.png (http://img59.imageshack.us/i/screenshotguy.png/)

Client code:


var xmlSock:XMLSocket = new XMLSocket();
var isRight:Boolean=false
var isLeft:Boolean=false
var isUp:Boolean=false
var isDown:Boolean=false
player.x = 50;
player.y = 50;
trace(player.x);
trace(player.y);

xmlSock.addEventListener(DataEvent.DATA, incomingData);
xmlSock.addEventListener(Event.CONNECT, Connected);
xmlSock.addEventListener(Event.CLOSE, connectionClosed);
xmlSock.addEventListener(IOErrorEvent.IO_ERROR, ioError);
connect_btn.addEventListener(MouseEvent.CLICK, connectClicked);
send_btn.addEventListener(MouseEvent.CLICK, sendClicked);
stage.addEventListener(KeyboardEvent.KEY_DOWN, downKey);
stage.addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(KeyboardEvent.KEY_UP, upKey);

function downKey(event:KeyboardEvent){
if(event.keyCode==39){
isRight=true}
if(event.keyCode==37){
isLeft=true}
if(event.keyCode==38){
isUp=true}
if(event.keyCode==40){
isDown=true}
}

function upKey(event:KeyboardEvent){
if(event.keyCode==39){
isRight=false}
if(event.keyCode==37){
isLeft=false}
if(event.keyCode==38){
isUp=false}
if(event.keyCode==40){
isDown=false}
}

function loop(Event){
if(isRight==true && player.x<450) {
player.x+=5
xmlSock.send(player.x);
}
if(isLeft==true && player.x>50) {
player.x-=5
xmlSock.send(player.x);
}
if(isUp==true && player.y>50) {
player.y-=5
xmlSock.send(player.y);
}
if(isDown==true && player.y<350) {
player.y+=5
xmlSock.send(player.y);
}
}

function ioError(evt:IOErrorEvent){
trace("IO Error: " + evt);
}
function connectionClosed(msg:Event){
incomingChat_txt.htmlText += "Connection closed";
}
function connectClicked(msg:Event) {
errorIndicator_mc.visible = false;

if (username_txt.text.length <= 0) {
errorIndicator_mc.visible = true;
return;
}

incomingChat_txt.htmlText += "Connecting to Server";
xmlSock.connect("127.0.0.1", 31337);

}
function Connected(msg:Event) {

incomingChat_txt.htmlText += "Connected";
connect_btn.enabled = false;
xmlSock.send(username_txt.text + " has connected\n");
xmlSock.send(player);
xmlSock.send(player.x);
xmlSock.send(player.y);

}
function sendClicked(msg:Event) {

if (sendChat_txt.text.length > 0) {

if(sendChat_txt.text.toLowerCase() == "exit"){
xmlSock.send("EXIT\n"); // server expects "EXIT", not "username~EXIT"
} else {
xmlSock.send(username_txt.text + ": " + sendChat_txt.text+"\n");
}

}

sendChat_txt.text = "";

}
function incomingData(evt:DataEvent):void {
trace("Incoming data ("+evt.type+"): " + evt.data);
incomingChat_txt.htmlText += evt.data;
player.x;
player.y;
}

Thanks, and sorry for my English language, not my base language. ;)

bluemagica
September 23rd, 2010, 08:04 AM
You are receiving the data alright, but you are not doing anything with the data.....that ball doesn't move on it's own. After you receive the data, you have to set it to the player's x/y if it is the client.

I suggest you use playerIO for now. after you get used to the concepts you can create your own server.

Keichioor
September 23rd, 2010, 11:35 AM
Ech, nothing think how to made, trying more variants but don't work(maybe a little AS3/Java/Networking skill's :) )
that as what a pity, but will stop this create and maybe learning more ActionScript 3.0, Java and about Networking.
Very very thanks you bluemagica for reply's,help and thanks who read this topic. ;)