c# - Reading incoming data from socket? -


i have socket client , wondering correct approach read incoming data it.

currently using follow function:

private void _readresponsepackets() {     while (_socket.connected)     {         try         {             byte[] bytes = new byte[1500];             _socket.receive(bytes);             if (bytes.length > 0)             loginserverpackets.enqueue(bytes);         }         catch (exception ex)         {             _log.write(errortype.error, "[loginclient] " + ex.tostring(), true);         }     } } 

that called own thread:

thread _readdatathread = new thread(_readresponsepackets); _readdatathread.start(); 

as can see merelly reading , pilling packets received on queue list further threaded question here is:

  • should use thread.sleep in read function or leave ?
  • would impact more on performance or memory usage or using thread.sleep ?

any other toughts ?

please check following link, socket in blocking mode, don't need use thread.sleep. listener


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -