thread too slow on sockets help request

  • Thread starter Thread starter Matteo Italy
  • Start date Start date
M

Matteo Italy

Guest
Hello everyone.

I'm developing a server for mobile machines that implements a socket server to receive their connection, by using Visual Studio Express 2013.

It uses Net.Sockets.TcpListener.AcceptSocket to assign the connection to a Net.Sockets.Socket.
It start a new Threading.Thread for each new socket created, with a while cycle to receive, parsing and write data to the socket.
It uses the property x.Available to get the data count and reads that data with the x.Receive(buffer, datalen, Net.Sockets.SocketFlags.None).
It parses the data received and create the answer.
Finally it uses the x.Send(answerbuffer, answerdatalen, Net.Sockets.SocketFlags.None) to transmit the answer.

The code works correcty on receive and send the answer, but it is quite slow.

I put some check on the code to get the elapsed time on each operation of the code and I get that average values:
- socket read and copy data from buffer to a list (of bytes): 100-200 ms
- data parsing and creating of an answer buffer list (of bytes): 150-300 ms
- converting buffer list (of bytes) to buffer array of bytes and socket send: 70-200 ms

Keeping in mind data receive for packet is about 150 byte length and data transmit is about 100 byte length, the timings for each execution part of the thread are quite high. So when the server receives more connections toghether, the answers slows down or stops for a while.

Does this method of using a Socket and a Thread for each connection on the server is bad?
Do I make a search of some other class to manage the data streaming or thread parallel executions?
Does visual studio express have some limitation on working with threads?

Thank you for the help.
Matteo

Continue reading...
 

Similar threads

M
Replies
0
Views
59
Matteo Italy
M
P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
Back
Top