firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
If I am reading correctly, you want to show packet as an int, via this
function?
void filter(char* packet)
{
while(*packet != 0)
{
cout << "(" << int(*packet) << ")";
packet++;
}
cout << endl;
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Is the string a char of digits or characters?
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
void filter(char* packet)
{
int i = 0;
while(packet[i])
{
cout << "(" << int(packet[i]) << ")";
i++;
}
cout << endl;
}
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Then your problem is the buffer thats being passed to it. I does
not contain what you want.
I assume that the problem is here:
bytesReceived = recvfrom(incs.cl, buffer, 1024, 0, (struct sockaddr *)&clSockAddr, &fromlen);
Check if bytesReceived is the correct number of bytes you want to recieve.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
"will evaluate to false when packet[i]==0"
Yes thats correct. The 0 identifies the end of the string. Any further
then its junk.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
when I do
void filter(char* packet)
{
for(int i = 0; i < 8; i++)
{
cout << "(" << int(*packet) << ")";
packet++;
}
cout << endl;
}
It print's
(83)(65)(77)(80)(127)(0)(0)(1)
though, so that would mean the buffer contains that information right?
Thats weird. Try cout<
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
I think you're all missing the point. Sockets doesn't send immediately.
Send Packet 5
Send Packet 8
Send Packet 7
It won't necessarily arrive as three packets 5 then 8 then 7 bytes in length.
It may arrive as 2 packets 5+8=13 and 7
or 5 and 15
or a single packet 20 bytes long!
The packet is sent on an interval basis, not immediately so sometimes packets get combined as a single packet of multiple messages!
So instead!
void filter( char* packet, uint nPacketLen )
{
while (nPacketLen)
{
while ((*packet != 0) && nPacketLen)
{
cout << "(" << int(*packet) << ")";
packet++;
nPacketLen--
}
cout << endl;
}
}
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99