Quote:Original post by Kylotan
Is your problem solved then? Or do you have further questions?
Yeah this one is solved. Now further issue is that after receiving message it freezes(as if it would enter infinite loop). Seems to happen when trying to read network for next time. Not sure what's up with that though I have few ideas where to look.
BTW could that be result of memory issues? I'm used for that causing segfaults but could it cause freezing of program instead?
Edit: Is it possible that the
result=SDLNet_TCP_Recv(mySocket, readBuffer+bytesRcvd, 1);
line would enter into blocking mode despite having passed:
if(SDLNet_CheckSockets(mySet, 0)>0) { printf("Activity in set!\n"); if(SDLNet_SocketReady(mySocket)!=0) {
Ie it would wait there 'till there's activity rather than existing the while loop?
Edit: Guess it was. I changed read method to:
int player::readNetwork() { int result=0; int bytesRcvd = 0; if(readBuffer==NULL) { readBuffer=new char[MAX_PACKET_SIZE+1]; } strcpy(readBuffer, ""); do { if(SDLNet_CheckSockets(mySet, 0)>0) { if(SDLNet_SocketReady(mySocket)!=0) { result=SDLNet_TCP_Recv(mySocket, readBuffer+bytesRcvd, 1); readBuffer[bytesRcvd+1]='\0'; if(result==0) { SDLNet_TCP_DelSocket(mySet,mySocket); SDLNet_TCP_Close(mySocket); return -1; } bytesRcvd+=result; } } else { return 0; } } while(!strchr(readBuffer, '\n') && bytesRcvd<MAX_PACKET_SIZE); return result;}
And it works. If somebody could confirm wether I figured reason correctly and I didn't just hide mistake badly I would appreciate it though. Just to be safe side that I have it working now. Networking has caused tons of headaches(especially before I added: readBuffer[bytesRcvd+1]='\0'; Before that line I got tons of extra trash causing rather...Random...workings when sending very long messages).
Edit: And I'll cheer here since I have to cheer somewhere :D Program is starting to approach the point where server and client finally discuss and I have something visible out of it :D Over 9k lines it has taken(mostly to get basic stuff needed done. GUI, graphic engine, network engine etc) but finally groundwork is starting to be done(well atleast done well enough) and I can start adding stuff that is visible!
Edit: Further thought on the error I think what happened was that after string containing first commands there still was '\0' character left. It therefore noticed activity, went to pick and then without further activity went to blockind mode. Whoops! Makes sense. '\0' is last character in char arrays but I read strings to '\n'. Therefore after I encounter '\n' and go out of read loop the '\0' is left unread and causes it to go wait for further activity.
Again if somebody sees error in this logic please do tell.
[Edited by - tneva82 on April 20, 2009 1:19:22 PM]