Jump to content
  • Advertisement
Sign in to follow this  

actionscript 3 client server Help

This topic is 3939 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!