class<Client, Message>Available in nekoThe ThreadServer can be used to easily create a multithreaded server where each thread polls multiple connections. To use it, at a minimum you must override or rebind clientConnected, readClientMessage, and clientMessage and you must define your Client and Message. var connectLag : FloatPolling timeout. var errorOutput : OutputStream to send error messages. var initialBufferSize : IntSpace allocated to buffers when they are created. var listen : IntNumber of total connections the server will accept. var maxBufferSize : IntMaximum size of buffered data read from a socket. An exception is thrown if the buffer exceeds this value. var maxSockPerThread : IntThe most sockets a thread will handle. var messageHeaderSize : IntMinimum message size. var nthreads : IntNumber of server threads. var updateTime : FloatTime between calls to update. function new() : VoidCreates a ThreadServer. function addSocket( s : Socket ) : VoidCalled when the server gets a new connection. dynamic function afterEvent() : VoidCalled after a client connects, disconnects, a message is received, or an update is performed. dynamic function clientConnected( s : Socket ) : ClientCalled when a client connects. Returns a client object. dynamic function clientDisconnected( c : Client ) : VoidCalled when a client disconnects or an error forces the connection to close. dynamic function clientMessage( c : Client, msg : Message ) : VoidCalled when a message has been received. Message handling code should go here. dynamic function onError( e : Dynamic, stack : Array<StackItem> ) : VoidCalled when an error has occurred. dynamic function readClientMessage( c : Client, buf : Bytes, pos : Int, len : Int ) : { msg : Message, bytes : Int }Called when data has been read from a socket. This method should try to extract a message from the buffer. The available data resides in buf, starts at pos, and is len bytes wide. Return the new message and the number of bytes read from the buffer. If no message could be read, return null. function run( host : String, port : Int ) : VoidStart the server at the specified host and port. function sendData( s : Socket, data : String ) : VoidSends data to a client. function stopClient( s : Socket ) : VoidShutdown a client's connection and remove them from the server. dynamic function update() : VoidThis method is called periodically. It can be used to do server maintenance. function work( f : Void -> Void ) : VoidInternally used to delegate something to the worker thread.
version #13453, modified 2012-04-12 22:31:17 by api
0 comment