Cant get a PONG

This is a discussion on Cant get a PONG within the Networking/Device Communication forums, part of the General Programming Boards category; Hi all! I'm trying to get a PONG anwser but it doesn't work Here is my code from my simple ...

  1. #1
    x77
    x77 is offline
    Registered User
    Join Date
    Jul 2007
    Posts
    8

    Cant get a PONG

    Hi all!

    I'm trying to get a PONG anwser but it doesn't work

    Here is my code from my simple ircbot

    Code:
    printf("\n%s", timebuffer);
    
       if(strstr(timebuffer,"PING")!=NULL)
       {
       printf("\nPing recv");
       timebuffer[1] = 'O'; // From a PING answer to a PONG but it doesn't work
       write(fd,timebuffer, strlen(timebuffer));
       }
    I hope somebody can help me.

    Thanks for all

    x77

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    So what does "doesn't work" mean?

    Does it ever print "Ping recv" for example?
    Or does timebuffer sometimes contain garbage perhaps?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    x77
    x77 is offline
    Registered User
    Join Date
    Jul 2007
    Posts
    8
    Hi!

    It means
    This is an example:

    The server send a PING like
    PING :B335AC1B

    The client must answer with the same like
    PONG:B335AC1B

    So I only must change the I in PING to an O.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    And if PING isn't right at the start, which strstr() can give you, then what?

    Debug the code and trace out what happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    x77
    x77 is offline
    Registered User
    Join Date
    Jul 2007
    Posts
    8
    It only prints out at stdout


    :irc.test.net NOTICE AUTH :*** Looking up your hostname...
    :irc.test.net NOTICE AUTH :*** Found your hostname
    PING :X7019375
    -------------------------------------------------------------------------

    Does it ever print "Ping recv" for example?

    No I don't see this Ping recv
    Last edited by x77; 07-22-2007 at 01:48 PM.

  6. #6
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    perhaps try using strstrn instead of strstr

    off the top of my head, it looks like you are comparing "PING" to "PING :X7019375"
    try
    Code:
    if(strstrn(timebuffer,"PING", 4)!=NULL)
    Quote Originally Posted by x77 View Post
    Does it ever print "Ping recv" for example?

    No I don't see this Ping recv
    Then the condition in the if statement is returning false(non-zero?)
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  7. #7
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Code:
    char *strstr(const char *s1, const char *s2);
    That function returns a pointer to the first occurance of s2 in s1. AFAIK, there is no function "strstrn".

    The OP needs to do some debugging, or post more code. I'd first switch around the printf() statements. Place the \n's at the end, (stdout is buffered) so that you're sure it gets printed. Better, send it to stderr. Better, just fire up a debugger and set a breakpoint inside the if() statement. If it never breaks, then what you think is in the buffer doesn't correspond to what's actually there.

    Then the condition in the if statement is returning false(non-zero?)
    False would mean the condition returned 0. Non-zero in an if statement means true.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  8. #8
    x77
    x77 is offline
    Registered User
    Join Date
    Jul 2007
    Posts
    8
    Hi!

    Thank you for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Space Pong (Debug) Release
    By Jeremy G in forum Game Programming
    Replies: 6
    Last Post: 10-02-2005, 08:14 PM
  2. The Story Of Pong (my game cookie)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-17-2005, 12:14 AM
  3. pong
    By lambs4 in forum Game Programming
    Replies: 2
    Last Post: 06-02-2003, 05:00 PM
  4. Battle Pong
    By DOlson in forum Game Programming
    Replies: 13
    Last Post: 01-08-2003, 11:32 PM
  5. God pong -update
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-03-2001, 10:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21