Here's a small Client/Server Application that demonstrate the use of the class

The Client :

// file Client.hx

class Client {

static function main() {

var s = new;


while( true ) {

var l = s.input.readLine();


if( l == "exit" ) {

s.close(); break;





The Server :

// file Server.hx class Server { static function main() { var s = new; s.bind(new"localhost"),5000); s.listen(1); trace("Starting server..."); while( true ) { var c : = s.accept(); trace("Client connected..."); c.write("hello\n"); c.write("your IP is "+c.peer().host.toString()+"\n"); c.write("exit"); c.close(); } } }

The HXML file to build the two projects :

  1. client_server.hxml

-neko client.n -main Client.hx

--next -neko server.n -main Server.hx

You can compile using the following command :

haxe client_server.hxml

Then open two terminals, in the first one you can start the server by running :

neko server.n

And in the second one you can start a client by running :

neko client.n

The server is sending to the client some datas that the client is printing, and when "exit" is received, the client exit and the server wait another client.

Multiple Clients Edit

If you want to be able to talk to several clients at the same time you can either the use method for multiplexing and/or the /api/neko/vm/Thread api to create multiple running threads.

See also the /doc/flash/chat

Community content is available under CC-BY-SA unless otherwise noted.