Question: Flash with Java

Hello,
I’m trying create simple Flash AS 3.0 Client / XMLSocket with Java programming language and Java socket’s, but i’m newbie in Java programming and for my hard create Java socket’s and i’m too learning programming with AS 3.0 :slight_smile:
OK, my question for this topic :slight_smile:
I’m use simple Java socket from Adobe.com
This simple Java socket from Adobe.com

import java.io.*;
import java.net.*;

class SimpleServer
{
    private static SimpleServer server;
    ServerSocket socket;
    Socket incoming;
    BufferedReader readerIn;
    PrintStream printOut;

    public static void main(String[] args)
    {
        int port = 8080;

        try
        {
            port = Integer.parseInt(args[0]);
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
            // Catch exception and keep going.
        }

        server = new SimpleServer(port);
    }

    private SimpleServer(int port)
    {
        System.out.println(">> Starting SimpleServer");
        try
        {
            socket = new ServerSocket(port);
            incoming = socket.accept();
            readerIn = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
            printOut = new PrintStream(incoming.getOutputStream());
            printOut.println("Enter EXIT to exit.\r");
            out("Enter EXIT to exit.\r");
            boolean done = false;
            while (!done)
            {
                String str = readerIn.readLine();
                if (str == null)
                {
                    done = true;
                }
                else
                {
                    out("Echo: " + str + "\r");
                    if(str.trim().equals("EXIT"))
                    {
                        done = true;
                    }
                }
                incoming.close();
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }

    private void out(String str)
    {
        printOut.println(str);
        System.out.println(str);
    }
}

Flash AS 3.0 client

import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;

var velocity:Number = 0;
var acceleration:Number = 0.5;
var friction:Number = 0.94;

var isRightKeyDown:Boolean = false;
var isLeftKeyDown:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function keyDownHandler(e:KeyboardEvent):void {
	if(e.keyCode == Keyboard.RIGHT) {
		isRightKeyDown = true;
	}
	if(e.keyCode == Keyboard.LEFT) {
		isLeftKeyDown = true;
	}
}
function keyUpHandler(e:KeyboardEvent):void {
	if(e.keyCode == Keyboard.RIGHT) {
		isRightKeyDown = false;
	}
	if(e.keyCode == Keyboard.LEFT) {
		isLeftKeyDown = false;
	}
}
function enterFrameHandler(e:Event):void {
	if(isRightKeyDown) {
		velocity += acceleration;
		if (velocity > 10) {
			velocity = 10;
		}
	} else if(isLeftKeyDown) {
		velocity -= acceleration;
		if (velocity < -10) {
			velocity = -10;
		}
	}
	velocity *= friction;
	this.x += velocity;
}

Client is with player(MovieClip) and can movement with key Left, Right and i’m trying multiplayer but i’m don’t know how to send to server and receive from server player…
I’m something like

xmlSocket.send(isLeftKeyDown)

and other xmlSocket.send(LEFT) , right and etc but how programming ?

Maybe any can more ask me how or maybe can anyone create simple example ?
Very very Thanks!