-
Non-Blocking Sockets
Hey all I need some help with setting information.
I receive data from client then I process it but for some reason when I get their username from a string. And Set a struct variable to keep it, the server crashes heres my processing code.
Code:
string data =(string)SocketInfo->DataBuf.buf;
string check = data.substr(0, 4);
int loc = data.find( "@", 0 );
if(datanum[0][0].compare(check)==0){
SocketInfo->username = data.substr(4,loc-4);
}
-
There's a separate forum for network programming.
-
Have you put 0 char into buffer before converting it to string?
Why do you not check that the symbol is found?
Why you don't check that the loc is actually >= 4?
-
chill out dude I have done that it just dosent go into the struct I get an error but when i output it using "cout" it displays the username correctly.
-
> string data =(string)SocketInfo->DataBuf.buf;
Let the compiler pick the right char array/pointer to string conversion, by removing the cast.
-
and I see no error checking there. what if if loc == string::npos? etc
-
Actually I got this working after looking it up I dont like strings so I went to see how to change String to char and found something and got that fixed. Now for all those that were wondering why no check well heres the thing it always has one the first if checks if its the right set of data to see if it should do that and extract username. But to understand all of it would make me tell you my whole project and wy im using @ lol. But ya thanks anyway.