🔒 Locked
Network game problem.
Advertisement
Original Post
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/
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
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
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
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
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
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
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;
}
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;
}
if(amount2==SOCKET_ERROR)
{
}
else
{
amount+=amount2;
}
}while(amount }
return amount;
}
argh u seem to have missde somthing here
does it say while(amount {is smaller then}nBufLen) this forum doesnt like certian characters it seems
coz if it does
then theres a problem
unless ure sending exactly 100 bytes of actual data in every packet
which i doubt
but if u are then i have no idea
anyways if u are sending something like 10 bytes for every packet
then that means ure server will first recieve 10 of those packets before it finishes the function
u shouldnt do that
just simply do a recv call and process the data u got
now as this is tcp/ip i dunno how to handle incomplete messages as tahts what happens
if u read one of the other threads ull c there
that u may send 10 packets but may only need to do one recv call or vice versa etc
but i did do a little bit of tcp but over a lan so that was not a problem
u can pretty much skip that for now
anyways
this should fix ure problem
however i dunno how this works line works
while(1==1);
not that c++ proficient
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
{
int amount2=recv(Socket,(char *)lpBuf,nBufLen,nFlags);
if(amount2==SOCKET_ERROR)
{
}
return amount;
}
and if ure really stumped then message here and leave ure email and ill send u a copy of an old pong game i made
very simple but the code is awful but its got a simple client/server thing
tho im not sure if i still have it
might have been a chat thing
dunno but ill c if i can find it if u need it
Hope this helps =)
Edited by - Do00d on January 6, 2002 8:47:10 AM
{
}
else
{
amount+=amount2;
}
}while(amount }
return amount;
}
argh u seem to have missde somthing here
does it say while(amount {is smaller then}nBufLen) this forum doesnt like certian characters it seems
coz if it does
then theres a problem
unless ure sending exactly 100 bytes of actual data in every packet
which i doubt
but if u are then i have no idea
anyways if u are sending something like 10 bytes for every packet
then that means ure server will first recieve 10 of those packets before it finishes the function
u shouldnt do that
just simply do a recv call and process the data u got
now as this is tcp/ip i dunno how to handle incomplete messages as tahts what happens
if u read one of the other threads ull c there
that u may send 10 packets but may only need to do one recv call or vice versa etc
but i did do a little bit of tcp but over a lan so that was not a problem
u can pretty much skip that for now
anyways
this should fix ure problem
however i dunno how this works line works
while(1==1);
not that c++ proficient
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
{
int amount2=recv(Socket,(char *)lpBuf,nBufLen,nFlags);
if(amount2==SOCKET_ERROR)
{
}
return amount;
}
and if ure really stumped then message here and leave ure email and ill send u a copy of an old pong game i made
very simple but the code is awful but its got a simple client/server thing
tho im not sure if i still have it
might have been a chat thing
dunno but ill c if i can find it if u need it
Hope this helps =)
Edited by - Do00d on January 6, 2002 8:47:10 AM
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement