Thread: not recving/sending and errno = 0

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    Thumbs up (NVM SOLVED) not recving/sending and errno = 0

    This is my first time doing any sort of network programming
    I have both a server and a client that can connect to each other, the client can send data to the server but not vice versa

    server:
    Code:
    void Init_Network()
    {
        if (WSAStartup(MAKEWORD(2,2), &WSAData) == SOCKET_ERROR)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    
        SockFD = socket(PF_INET, SOCK_STREAM, 0);
        if (SockFD == SOCKET_ERROR)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    
        memset(My_Addr.sin_zero, '\0', sizeof My_Addr.sin_zero);
        My_Addr.sin_family = AF_INET;
        My_Addr.sin_port = htons(Port_Number);
        My_Addr.sin_addr.s_addr = INADDR_ANY;
    
        if (bind(SockFD, (struct sockaddr *)&My_Addr, sizeof(struct sockaddr)) == SOCKET_ERROR)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    
        if (listen(SockFD, 5) == SOCKET_ERROR)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    }
    Code:
                    //send
                    OutMessage[0] = 'c';
                    OutMessage[1] = MyPos.X;
                    OutMessage[2] = MyPos.Y;
                    OutMessage[3] = '\0';
                    nBytes = send(SockFD, OutMessage, 20, 0);
                    std::cout<<errno;
                    memset(OutMessage, ' ', 20);
    client:
    Code:
    void Init_Network()
    {
        if (WSAStartup(MAKEWORD(2,2), &WSAData) == SOCKET_ERROR)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    
        SockFD = socket(PF_INET, SOCK_STREAM, 0);
        if (SockFD == SOCKET_ERROR)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    
        Host_Entry = gethostbyname(IP);
        if (Host_Entry == NULL)
            MessageBox(0, "ERROR", "ERROR", MB_OK);
    
        Server_Addr.sin_family = AF_INET;
        Server_Addr.sin_port = htons(Port_Number);
        Server_Addr.sin_addr.s_addr = *(unsigned long*)Host_Entry->h_addr;
    }
    Code:
                    //recv
                    EnemyPrevPos.X = EnemyPos.X;
                    EnemyPrevPos.Y = EnemyPos.Y;
                    error = recv(ServerFD, InMessage, 20, 0);
                    if (error == 0)
                    {
                        std::cout<<"Your opponent has left the game."<<std::endl;
                        return 0;
                    }
                    if (error == -1)
                    {
                        char temps[50];
                        SetConsoleCursorPosition(hOut, tempC);
                        perror(temps);
                        std::cout<<temps<<std::endl;
                        std::cout<<errno<<std::endl;
                        //return 0;
                    }
                    switch (InMessage[0])
                    {
                        case 'c':
                            EnemyPos.X = InMessage[1];
                            EnemyPos.Y = InMessage[2];
                            break;
                        default:
                            SetConsoleCursorPosition(hOut, tempC);
                            std::cout<<InMessage;
                            break;
                    }
                    memset(InMessage, ' ', sizeof InMessage);
    Last edited by h_howee; 06-09-2007 at 04:45 PM. Reason: misspelled [/code]

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    oops, i passed the wrong FDs to the send and recv function...

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. errno function, error TLS/non TLS
    By fran.b in forum C Programming
    Replies: 13
    Last Post: 03-25-2009, 08:06 AM
  2. /usr/bin/ld: errno: TLS definition in /lib/libc.so.6
    By nasim751 in forum C Programming
    Replies: 4
    Last Post: 02-25-2009, 04:15 AM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. where from extern int errno came ?
    By jabka in forum C Programming
    Replies: 2
    Last Post: 10-14-2007, 05:25 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM