|
-
September 15th, 2015, 07:10 AM
#1
SIGSEGVs, missing parts of input
Hello wise people!
Got a problem with my winsock client program. It looses parts of input. Here's the important (IMO) part of the code:
Code:
...
string nickname;
if(connect(socketDeskryptor,(struct sockaddr*)&dest_addr,sizeof(struct sockaddr))==-1)
{
cout<<"ERROR! Failed to connect to the server error nr "<<WSAGetLastError()<<endl;
system("pause");
exit(1);
}
else
{
cout<<"connected!"<<endl;
ReceiverHandle=CreateThread(NULL,0,ReceiverThread,&socketDeskryptor,0,NULL); // a thread to handle server response
cout<<"You have to select a nickname to use first(enter blank to use your IP as nickname)"<<endl;
NICKNAME_SELECTION:
nickname.clear();
cin.ignore();
getline(cin,nickname);
if(nickname.length()>20)
{
cout<<"You have exceeded the maximum ammount of 20 characters to be used as your nickname.Try again."<<endl;
goto NICKNAME_SELECTION;
}
send(socketDeskryptor,nickname.c_str(),20,0);
nickname.clear();
}
string message;
while(1) //message loop
{
message.clear();
cin.ignore();
getline(cin,message);
if(message=="EXIT")
{
break;
}
if(message.length()>200)
{
cout<<"You've exceeded the maximum ammount of 200 characters in a single message.Message won't be sent"<<endl;
message="";
continue;
}
cout<<"This is the message to send: "<<message<<endl;
send(socketDeskryptor,message.c_str(),200,0);
}
return 0;
}
During debugging it also shows multiple SIGSEGV errors, even though it compiles just fine. Also the nickname selection part seems to work fine, i decided to include it for reference. The problem lies in the message loop. I'll give you an example console output.
connected!
You have to select a nickname to use first(enter blank to use your IP as a nickname)
XXX
server response: 192.168.1.115 changed name to XXX!
Hello my name is George
this is the message to send: ello my name i George
server response: XXX said: ello my name i George
As you can see it "bites off" single letters from the message. And I have no idea why . I've been searching for the solution for en ethernity now.
x240-oI6.jpg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|