Thread: socket connection error

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    11

    Question socket connection error

    I have a server and when I try to connect to the server with a lient with connect function it returns a value of '1' I read the definition of connect, it says that upon uccessful completion it return 0 or else -1. I'm confused because what I get is neither of these. can this '1' be a error number. if so any one knows what it is or how can find out what the error is?? thank you

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    11
    well disregard this post Its a -1 I get not a 1 ..... sorry

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    11
    but can some one tell me how to find what faied. I mean why did connect() faied ???

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    OS Dependant.

    WSAGetLastError/errno.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    11
    I dint understant what u said I'm using FC5

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    11

    socket connection error

    this is my code.... nothing major just want to test my server

    Code:
    void main()
    {
       int soc, n, t, d;
       char *er;
       char recvline[51], *address= {"127.0.0.1\n"};
       struct sockaddr_in serveradd;
       //struct sockaddr SA;
    
       if(soc= socket(AF_INET, SOCK_STREAM, 0)<0)
       {
          printf("socket error\n");
       }
    
       serveradd.sin_family = AF_INET;
       serveradd.sin_port = htons(3879);
       //serveradd.sin_addr= &address;
    
       if((t = inet_pton(AF_INET, address, &serveradd.sin_addr)<=0))
       {
          printf("pton eror for %d\n", t );
       }
    
       if(d =connect(soc, (struct sockaddr *)&serveradd, sizeof(serveradd)))
    
          printf("connection error %d", d);
          //err_sys("%c", er);
    
    
    
        recv(soc, &recvline, 51, MSG_WAITALL);
       /*{
          printf("data : %c ", n);
       }*/
    
       close(soc);
    }

  7. #7

  8. #8
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    "OS dependent" means...

    The value of errno is dependent on the implementation. On any UNIX variant you can use perror() to display a nice error message or any Windows system, you can get the error number by WSAGetLastError().

    Your code looks like a UNIX code, so use perror().

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. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM