ServerLoop

class neko.net.ServerLoop<ClientData>Available in nekoThis class enables you to quickly create a custom server that can serve several clients in parallel. This server is using a single thread and process so the server itself processing is not parallel. Non-blocking sockets are used to ensure that a slow client does not block the others. var clients : List<ClientData> var listenCount : IntThis is the value of number client requests that the server socket listen for. By default this number is 10 but can be increased for servers supporting a large number of simultaneous requests. var updateTime : FloatSee update. function new( ?newData : Socket -> ClientData ) : VoidCreates a server instance. The newData methods must return the data associated with the Client. function clientDisconnected( d : ClientData ) : VoidThis method is called after a client has been disconnected. function clientWrite( s : Socket, buf : Bytes, pos : Int, len : Int ) : VoidThis method can be used instead of writing directly to the socket. It ensures that all the data is correctly sent. If an error occurs while sending the data, no exception will occur but the client will be gracefully disconnected. function closeConnection( s : Socket ) : BoolCloses the client connection and removes it from the client List. function onError( e : Dynamic ) : VoidCalled when an error occured. This enable you to log the error somewhere. By default the error is displayed using trace. function processClientData( d : ClientData, buf : Bytes, bufpos : Int, buflen : Int ) : IntThis method is called when some data has been readed into a Client buffer. If the data can be handled, then you can return the number of bytes handled that needs to be removed from the buffer. It the data can't be handled (some part of the message is missing for example), returns 0. function run( host : Host, port : Int ) : VoidRun the server. This function should never return. function update() : VoidThe update method is called after each socket event has been processed or when updateTime has been reached. It can be used to perform time-regular tasks such as pings. By default updateTime is set to one second. static var DEFAULT_BUFSIZE : IntEach client has an associated buffer. This is the initial buffer size which is set to 128 bytes by default. static var MAX_BUFSIZE : IntEach client has an associated buffer. This is the maximum buffer size which is set to 64K by default. When that size is reached and some data can't be processed, the client is disconnected.
version #19266, modified 2013-05-08 11:10:30 by api
0 comment