Sign in to follow this  

actionscript 3 client server Help

This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need help creating server and client for simple version of it. In actionscript 3 format. That can send and revive the message. Can any help me on this part. I just found this just for the client but not sure about the server side. package { import flash.events.Event; import flash.net.Socket; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.display.Sprite; public class DemoClient extends Sprite { private var host:String; private var port:int; private var socket:Socket; public function DemoClient() { host = "localhost"; port = 5555; connect(); } private function sendMessage( message:String ):void { message = "message" + ";" + message + "\n"; if ( socket && socket.connected ) socket.writeUTFBytes( message ); } private function receiveMessage( message:String ):void { trace( message ); } private function connect():void { socket = new Socket(); socket.addEventListener(Event.CONNECT, socketConnect); socket.addEventListener(Event.CLOSE, socketClose); socket.addEventListener(IOErrorEvent.IO_ERROR, socketError ); try { socket.connect(host, port); } catch (e:Error) {} } private function socketConnect( event:Event ):void { // handle connection connected socket.addEventListener( ProgressEvent.SOCKET_DATA, socketData ); sendMessage( "Hello Server" ); } private function socketData( event:ProgressEvent ):void { receiveMessage( socket.readUTFBytes( socket.bytesAvailable ) ); } private function socketClose( event:Event ):void { // handle connection closed trace( "Socket Closed" ); } private function socketError( event:IOErrorEvent ):void { // handle connection error trace( "Socket has run into an Error" ); } } }

Share this post


Link to post
Share on other sites

This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this