Haxe Websockets (Part 2)

Posted on Nov 24, 2010

Read this post for Part 1…

I have just updated the haxe websocket code significantly. I have made a websocket compatible ThreadServer and ThreadRemotingServer, and included some different examples of using these classes.

The websocket.ThreadServer class can be used to easily set up a server that sends and receives messages from connected clients. There are two examples “echo” and “cursors” that demonstrate how to use it. For example to setup a basic websocket echoing server:

class EchoServer
{    
 public static var server:ThreadServer;
 public static function main()
 {
  server = new ThreadServer();
  server.onMessage = function(c:Client, m:String) {
   server.sendMessage(c, m);
  };
  server.run("localhost", 5001);
 }    
}