Re: client-server work locally but client crashes if launched elsewhere.
Sure, the analysis is simple: your program has a bug in it, somewhere. Figure out what
went wrong and fix it.
If you expect us to help, you would, of course, give us ALL THE DETAILS of what you mean
by "crash". Was it an access fault? Where did it happen? What was the call stack at
that point? What were the values of the relevant variables? Was it an assertion failure?
What line did it occur on? What was the call stack at that point? What were the values
of the relevant variables?
There is no more useless term to describe a problem than the unqualified word "crash".
There is no such thing. There are access faults, stack overflows, assertion failures,
divide-by-zero faults, among the most common ones, and when one of these failures occurs,
there are specific lines of code, in specific files, with specific values of variables,
called from specific paths, involved. Lacking anything other than the mysterious word
"crash", there is NO WAY TO TELL WHAT HAPPENED! We cannot even BEGIN to suggest what
might have happened!
Hint: if you did not properly check for success on critical operations, such as
connections, receiving data, allocating storage, etc., well, you have a bug in your code,
which is inadequate error checking and recovery. But lacking anything at all that would
be a useful description of the problem, there is zero chance of getting any help.
Thanks. Sorry for that description, I thought this could be an common
error. The problem is that it is hard to test my program remotely, as
I don't have another LAN mashine near. But, I found out that critical
error is here:
char *c=new char[len];//len is a variable integer
bytesReceived=recv(socket,c,len,0);
if(bytesReceived==SOCKET_ERROR||bytesReceived<len){
::MessageBox(NULL,"Error!!!","Alert",NULL);
int err=GetLastError();/////////////// this always is 0!!!!
string error="Error ";
char ch[10];
itoa(err,ch,10);
error=+ch;
::MessageBox(NULL,error.data(),"Alert",NULL);
}
So I check for len/received and get: 32472/18980, 32772/ 11680,
32874/11680. I don't know why but client doesn't receive all the bytes
and this is why my further code "crashes" due to index exceeding on
std:string. Server however doesn't encount such problems, it sends all
the bytes needed.