Jump to content
  • Advertisement
Sign in to follow this  
fathom88

CSocket Class And Thread Priority Question

This topic is 4799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm created a custom CSocket class to read data over an Ethernet connection. I use the data to draw an image to the screen via OpenGL. The image I'm drawing has empty spots. I placed a trace inside my over-ride of OnReceive and noticed some strange behavior. The data coming over the wire is internally tagged. Hence, tracking missing packets is a simple task of reading the packet header. I noticed that when the drawing routine is not running, the packet header indicates all packets arrived. However, when the drawing thread is running, I get missing packets. I'll get packet 1401, 1402, then it'll skip to packet 2345. These massive skips in data then translate into empty holes in the image I'm drawing. The packet seem to be lost at the point they come into the socket class. However, I'm not sure what's causing it. My OpenGL drawing thread exists in another class and thread. Could my drawing thread be taking enough time slices away from my socket class as to cause this problem? I did a test where I did not enable the draw thread, but I placed a sleep inside the OnReceive call and it generated the same dropped packets problem. Any suggestions? Thanks. Using VC++.

Share this post


Link to post
Share on other sites
Advertisement
Im not an expert on networking, but i'll try to help:)

What it might happen is that you send all data so fast from other side that you
dont process the incoming data as fast, and your socket queue can get filled up, and then windows dont accept anymore packets...
(i hope you understand what im trying to tell you)

Share this post


Link to post
Share on other sites
Is there a way to increase the queue? I have two separate threads; one to read the data over the socket and one to draw the data. My Trace statement is inside the socket thread. I read the data and deposit inside it inside a DataRepository class which the draw thread also has access to. The packets have an incrementing ID number and return to zero when a new image is going down the socket. My socket reading thread does not wait for the draw thread. It is constantly placing data inside the DataRepository class. I had thought maybe there was a problem with accessing the data class. Then, I replaced my draw thread with a sleep loop for a small amount of time. Instead of drawing, it just sleeps and does not access the data class; yet the problem was still present. Now, here is the strange part. When I reduced the sleep to an extremely low number (1 in this case), the problem went away. Thanks for the help anyways. I think it might be a thread issue. Thanks again.

Share this post


Link to post
Share on other sites
Well if you run out of options, you can try make sender wait for cofirmation that he is able to recieve more data

Good luck!

Share this post


Link to post
Share on other sites
Are you sending raw ethernet packets? Or are you using UDP or TCP?

If you are using datagrams, raw ethernet or UDP, then you need to build flow-control into your sending algorithm. TCP has flow-control built-in among other features.

You should also calculate the amount of data you are sending over the network. Up to about 50Mbps should work on a small LAN, after that it can become problematic, and you have to write advanced networking code to break 80Mbps (sustained). Higher traffic levels will also be more adversely affected by other traffic on the network.

Increasing the priority of your socket thread is a good idea though, generally any blocking or asyncronous operations should be given a priority boost (do work when needed), whereas infinite task (such a a game-loop) should be reduced in priority (consume all idle). This will not solve your fundmental problem though (flow-control, error-correction, re-transmission, e.g. try TCP).

Share this post


Link to post
Share on other sites
Thanks for the suggestion. In CSocket's create, I'm using the SOCK_STREAM flag which is TCP as I recall. I calculate on average I'll get 2.5 M over the wire every second, which is a reasonable amount of data. As for increasing thread priority, how does one increment the CSocket's thread priority? I used CSocket as a base class and re-wrote the OnReceive call to drop data into my DataRepository class. I didn't see any methods concerning thread priority at the MSDN help page. Thanks.

Share this post


Link to post
Share on other sites
My Basic Socket Layer implementation for my MUD engine. It uses TCP (and yes, SOCK_STREAM is TCP). The IMC2 client also has some networking handling in there, but it connects via TCP to a router.

Share this post


Link to post
Share on other sites
I solved the problem by writing my own socket class from the ground up. I ported some old UNIX code over and made a read thread using the select call. All I had to do was increase the thread priority to time critical. This fixed my problem. I was scared the CPU uitilization would shoot up, but it did not. Thanks for all the help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I'm having the same problem with CSocket class. Would you mind showing me your socket class that is working? Thanks. My email is sherong@yahoo.com

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!