Thread: socket error

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    socket error

    I am tring to create a program that will let me loggin to irc... but.. i keep getting

    Connecting to server...
    NOTICE AUTH :*** Looking up your hostname.....
    NOTICE AUTH :*** Checking Ident
    NOTICE AUTH :*** Found your hostname
    NOTICE AUTH :*** Got Ident response

    ERROR :Closing Link: [[email protected]]

    well i made it that far to get it connected.. but it wont give me all the info that it should.. so that i can join a chan etc..

    anyways.. here is the code ( please take it easy im new to socket and am really stressed about not remembering somethings so streesed i can cry)

    Code:
    #define MYPORT 6667
    
    int main( )
    {
    
        struct sockaddr_in mysock;
         struct sockaddr_in tosock;
         struct hostent *addr;
         int s_sock, s_conn, x;
         int len, s_send, s_recv;
         char *p_buff, buff[525];
         char *msg;
         
         
         if((s_sock = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
         {
           fprintf( stderr, "Error on SOCKET( )" );
            return 1;
         }
         
        /* fgets( buff, 20, stdin );
         printf("xlordt suxz 1\n");
         */
         mysock.sin_family = AF_INET;
         mysock.sin_port = htons( MYPORT );
         mysock.sin_addr.s_addr = inet_addr( "66.252.6.72" );
         
         if((s_conn = connect( s_sock, ( struct sockaddr *)&mysock, sizeof mysock)) == -1 )
         {
            fprintf( stderr, "Error on SOCKET( )" );
            return 1;
         }
         
         printf( "Connecting to server...\n" );
         
         p_buff = buff;
         p_buff = (char *)malloc( 64 * sizeof( char ));
         for( x=0; x < 25; x++ )
         {
           if((s_recv = recv( s_sock, p_buff, sizeof p_buff, 0 )) == -1 )
           {
              fprintf( stderr, "Error on RECV( )" );
              return 1;
           }
           
       
           printf( "%s", p_buff );
           msg = "PING";
           len = strlen( msg );
           send( s_sock, msg, len, 0 );
           recv( s_sock, p_buff, sizeof p_buff, 0 );
           printf( "%s", p_buff );
           
         }
        
         
         msg="/nick hmmmm";
         len = strlen( msg );
         
         if((s_send = send( s_sock, msg, len, 0 )) == -1 )
         {
            strerror( errno );
            return 1;
         }
         
         msg="/join #chan";
         len = strlen( msg );
         
         if((s_send = send( s_sock, msg, len, 0 )) == -1 )
         {
            strerror( errno );
            return 1;
         }
         
         return 0;
         
         close( s_sock );
      }
    I am just going crazy tring new $$$$ here.. =/
    Last edited by xlordt; 09-24-2003 at 10:52 PM.
    Only the strong survives.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> p_buff = buff;
    >> p_buff = (char *)malloc( 64 * sizeof( char ));

    Why do you point it to buff, then in the next breath to dynamic memory?

    Also, you didn't free the memory.

    >> if((s_recv = recv( s_sock, p_buff, sizeof p_buff, 0 )) == -1 )

    The sizeof(ANY POINTER) == 4.

    TCP is a *sliding window* protocol. You may send 255 bytes, but the other end may recieve these in 127 bytes chunks, and vice-versa. The point is, you are supposed to do your own book keeping, and build your buffer as the reception proceeds.

    My advice is to put this project on the backburner, re-read your C-programming books, and try to build some real skills so that when you *really* need to do something like this, you will be able to pull it off with a least a modicum of competence.

    Cheers.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    Ya in a way your right.. but.. when i post something that i get from a book.. to test it out.. and it doesnt work.. i get questions like... why you do that ... why you did this... kinda confusing.. hmm heh anyways.. i will keep tring.. thanx =) eventually i will get it.. i just wish these damn books were a bit more straight forward( or should i say... a bit more less error less )
    Only the strong survives.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM