| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 06, 2008 9:55 pm Post subject: winscok data fuckery |
|
|
I making server/clinet applications and it's working fine. Just I'm getting this data fuckery whenever I receive and send stuff. Look...
My code for receiving and sending on the server and client is:
| Code: |
//SERVER
Result = recv(ClientSocket, recvbuf, DEFAULT_BUFLEN, NULL);
std::cout<<"Data recieved: "<<recvbuf<<"\n";
std::cout<<"Bytes recieved: "<<Result<<"\n";
std::cout<<"Sending back data...";
SendResult = send(ClientSocket, recvbuf, Result, NULL);
std::cout<<"\nData sent!\n";
std::cout<<"Data sent: "<<recvbuf<<"\n";
std::cout<<"Bytes sent: "<<SendResult<<"\n";
|
| Code: |
//CLIENT
SendResult = send(ConnectSocket, sendbuf, strlen(sendbuf), NULL);
std::cout<<"Data Sent: "<<sendbuf<<"\n";
std::cout<<"Bytes Sent: "<<SendResult<<"\n";
std::cout<<"Receiving data...";
Result = recv(ConnectSocket, recvbuf, DEFAULT_BUFLEN, NULL);
std::cout<<"\nData recieved: "<<recvbuf<<"\n";
std::cout<<"Bytes Recieved: "<<Result<<"\n";
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Sun Jul 06, 2008 10:11 pm Post subject: |
|
|
I dont think your buffer is receiveing a null terminator.
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Jul 06, 2008 10:54 pm Post subject: |
|
|
That would cause a buffer overflow, but the outputted character wouldn't be the same all the time though right? And I changed it to receive with DEFAULT_BUFLEN+1 (handling the null character) but I still get the same error?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Jul 06, 2008 11:24 pm Post subject: |
|
|
You aren't null terminating the buffer, just like HalfPrime said. Which causes that to happen. You can easily null terminate it as needed based on the return from recv:
| Code: | | Result = recv(ConnectSocket, recvbuf, DEFAULT_BUFLEN, NULL); |
Then you would do, after that:
| Code: | | recvbuf[Result] = '\0'; |
_________________
- Retired. |
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Jul 06, 2008 11:26 pm Post subject: |
|
|
| I'm trying to do something similar and I got the concept, but haven't started yet. What do you plan on making?
|
|
| Back to top |
|
 |
|