Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

laeuchli

Network game problem.

This topic is 6009 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

Hey all, I''m trying to write a network game. I thought the network code would be easy, but apperantly not. Here is the problem. I''m running on a 100mps lan, and I''m getting performance problems. Here is how I''m doing it. I have a stand alone server, that uses IOCP. Basicly all it does, is get info, and pass it along to other players. Not cheat proof, but simple. In the client, I have one recive thread, and then I have the main process thread, which updates postion of player, and sends it along. The amount of data the client generates, and sends to the server is the same size all the time. The recive thread just keeps calling recive(normal winsock function), untill it fills the buffer, then starts over with a new buffer. In the main thread I have problems. I tried using send(normal winsock function), but sometimes the whole program locked up :-(. I tried putting the send stuff in a different thread, but nothing doing :-(. I figured the problem could be blocking, so I changed to WSASend non-blocking, and now I get a different problem. If I move the player on one computer the other computer won''t update for serveral minutes. Then it goes though what the other computer did. I figured turning off nagle would help, but it didn''t really. I don''t know what to do, or how I should be redesiging this(proably obvious to a winsock expert). Could someone help me out? Jesse www.laeuchli.com/jesse/

Share this post


Link to post
Share on other sites
Advertisement
Typically I design my game clients as follows:

Main Loop (Thread 1)
{

// processes input/rendering etc
// posts/retrieves asynchronous WSASend/WSARecv calls
// do physics/update object positions etc
// render

}

The asynchronous send and receives should help avoid having to use a second thread which minimizes thread context switching.

What protocol are you using?





Dire Wolf
www.digitalfiends.com

Share this post


Link to post
Share on other sites
You might try taking a step back, and go with a more basic network/thread model in order to get the network code running, then tweak it from a known working state. Just a thought...

Share this post


Link to post
Share on other sites
why do u wait to completly fill up a buffer?
u should just make a call to recv and if u get something u process it or send it to a thread or whatever
if not then keep going
these blocking calls?

Share this post


Link to post
Share on other sites
well if ure blocking
and waiting for the whole buffer to fill up
then ure server will do recv calls untill the buffer is full thus not continuing the game
u should just use async sockets or some other type
again im a novice so dont take my advice as the only way or the better way etc etc
or just simply do one recv call and dont wait for it to fill up the whole buffer

Share this post


Link to post
Share on other sites
explain me this
what do u mean by fill up the buffer?
coz thats the only problem i c
u should be able to keep em in the same thread if its something simple
thats what im doing nmow as i have no idea about htreads
but soon ill transfeer my stuff into a nother thread
but anyways yeh can u explain wahts happening when u recieve data?
then i could help u

Share this post


Link to post
Share on other sites
Here is my recive code:
long WINAPI ReciveFunction(void *vArg)
{
do{
char messagel[100];
ClientSocket.Receive(messagel,100,NULL,false);
}while(1==1);
return 1;
}
int CIOSocket::Receive(void* lpBuf, int nBufLen, int nFlags, bool bAcceptPartial)
{
int amount=0;
if(bAcceptPartial==true)
{
amount=recv(Socket,(char *)lpBuf,nBufLen,nFlags);
}
else
{
do
{
int amount2=recv(Socket,(char *)lpBuf,nBufLen,nFlags);
if(amount2==SOCKET_ERROR)
{

}
else
{
amount+=amount2;
}
}while(amount }
return amount;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!