class AsyncSocket
package sys.net
Available on python, php, lua, hl, neko, jvm, cpp, macro
A TCP socket class : allow you to both connect to a given server and exchange messages or start your own server and wait for connections.
Static methods
staticstartServer(host:String, port:Int, ?ssl:{key:Key, hostname:String, cert:Certificate}, onClient:Null<AsyncSocket> ‑> Any):AsyncSocket
Start a server on given host/port and callback onClient everytime a client connects.
Will also call onClient(null) in the rare case where the server connection is lost.
Constructor
Methods
accept():Null<AsyncSocket>
Accept a new connected client. This will return a connected socket on which you can read/write some data. See listen
bind(host:Host, port:Int, ?ssl:{key:Key, hostname:String, cert:Certificate}):Void
Bind the socket to the given host/port so it can afterwards listen for connections there.
close():Void
Closes the socket : make sure to properly close all your sockets or you will crash when you run out of file descriptors.
connect(host:Host, port:Int, ssl:Bool = false):Void
Connect to the given server host/port. Will onConnect if connection successful and onDisconnect if connection fails or if a later disconnection occurs.
If ssl is set, the socket will use SSL authentification and encryption. Certificate errors can generate an onSSLError callback.
listen(connections:Int):Void
Allows the socket to listen for incoming questions. The parameter tells how many pending connections we can have until they get refused.
Each new connection will trigger a onConnected call. Use accept() to retrieve the incoming connection socket.
dynamiconData(bytes:Bytes, pos:Int, len:Int):Void
This callback is called when some data is received on the socket. The bytes must be fully processed in the callback as the data might be overwritten upon return.
dynamiconSSLError(msg:String):Void
Dispatched when a SSL error occurs. This can be when connecting to a host which fails to authentificate or when starting a server with invalid cert/key.
Authentification can be adjusted with sys.ssl.Socket.DEFAULT_VERIFY_CERT
dynamiconWrite(error:Bool):Void
Dispatched when some data is written. Error is true if the data could not be written succesfully. The default behavior is to silently close the socket when such error occurs.
setFastSend(b:Bool):Void
Allows the socket to immediately send the data when written to its output : this will cause less ping but might increase the number of packets / data size, especially when doing a lot of small writes.