943,902 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3297
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 12th, 2009
0

Re: Terminating Zero Problem

never mind what i'm saying
Last edited by harry010; Aug 12th, 2009 at 2:25 pm.
Reputation Points: 10
Solved Threads: 3
Light Poster
harry010 is offline Offline
35 posts
since Aug 2009
Aug 12th, 2009
0

Re: Terminating Zero Problem

That still doesn't work, it prints the first 5 characters, but not the following characters.

Currently it prints
(83)(65)(77)(80)(127)
which means:
SAMP and the 127 is the start from my local IP, which should be (127)(0)(0)(1).
Reputation Points: 10
Solved Threads: 3
Light Poster
Schoorsteen is offline Offline
44 posts
since Aug 2009
Aug 12th, 2009
0

Re: Terminating Zero Problem

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:
C++ Syntax (Toggle Plain Text)
  1. bytesReceived = recvfrom(incs.cl, buffer, 1024, 0, (struct sockaddr *)&clSockAddr, &fromlen);

Check if bytesReceived is the correct number of bytes you want to recieve.
Last edited by firstPerson; Aug 12th, 2009 at 2:14 pm.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Aug 12th, 2009
0

Re: Terminating Zero Problem

Sorry, i shouldn't be trying to answer this-I'm just confusing things with my nonsense responses.
Last edited by harry010; Aug 12th, 2009 at 2:19 pm.
Reputation Points: 10
Solved Threads: 3
Light Poster
harry010 is offline Offline
35 posts
since Aug 2009
Aug 12th, 2009
0

Re: Terminating Zero Problem

when I do
C++ Syntax (Toggle Plain Text)
  1. void filter(char* packet)
  2. {
  3.  
  4. for(int i = 0; i < 8; i++)
  5. {
  6. cout << "(" << int(*packet) << ")";
  7. packet++;
  8. }
  9.  
  10. cout << endl;
  11. }

It print's
(83)(65)(77)(80)(127)(0)(0)(1)
though, so that would mean the buffer contains that information right?
Reputation Points: 10
Solved Threads: 3
Light Poster
Schoorsteen is offline Offline
44 posts
since Aug 2009
Aug 12th, 2009
0

Re: Terminating Zero Problem

"will evaluate to false when packet[i]==0"

Yes thats correct. The 0 identifies the end of the string. Any further
then its junk.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Aug 12th, 2009
0

Re: Terminating Zero Problem

When I cout the receivedBytes I get this number 4294967295. Would this be right?
Reputation Points: 10
Solved Threads: 3
Light Poster
Schoorsteen is offline Offline
44 posts
since Aug 2009
Aug 12th, 2009
0

Re: Terminating Zero Problem

"will evaluate to false when packet[i]==0"

Yes thats correct. The 0 identifies the end of the string. Any further
then its junk.
Sorry, I didn't understand the original post at first. I shouldn't have posted anything.
Reputation Points: 10
Solved Threads: 3
Light Poster
harry010 is offline Offline
35 posts
since Aug 2009
Aug 12th, 2009
0

Re: Terminating Zero Problem

when I do
C++ Syntax (Toggle Plain Text)
  1. void filter(char* packet)
  2. {
  3.  
  4. for(int i = 0; i < 8; i++)
  5. {
  6. cout << "(" << int(*packet) << ")";
  7. packet++;
  8. }
  9.  
  10. cout << endl;
  11. }


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<<buffer before the function call , and in the function as well. See if they are the same.
Last edited by firstPerson; Aug 12th, 2009 at 2:24 pm.
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Aug 12th, 2009
1

Re: Terminating Zero Problem

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!
C++ Syntax (Toggle Plain Text)
  1. void filter( char* packet, uint nPacketLen )
  2. {
  3. while (nPacketLen)
  4. {
  5. while ((*packet != 0) && nPacketLen)
  6. {
  7. cout << "(" << int(*packet) << ")";
  8. packet++;
  9. nPacketLen--
  10. }
  11. cout << endl;
  12. }
  13. }
Last edited by wildgoose; Aug 12th, 2009 at 2:39 pm.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: sequence diagram help
Next Thread in C++ Forum Timeline: how to derive class from a derived class





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC