Getting error address already in use in socket programming


 
Thread Tools Search this Thread
Top Forums Programming Getting error address already in use in socket programming
# 1  
Old 01-23-2014
Getting error address already in use in socket programming

Hi ,

I am getting error in bind function of "Address already in use" even also i have used the setsockopt function in that case .

Please help

Code:
   int                     ret = 0;
    int                     listenSock = 0;
    struct sockaddr_in      myAddr;
    struct sockaddr_in      destAddr;
    int                     destAddrLen = sizeof( struct sockaddr_in );
     int                     yes = 1;

     retVal = socket( AF_INET, SOCK_STREAM, 0 );
    if ( -1 == ret )
    {
        perror( "Error from socket system call " );

        return ret;                 /**** RETURN POINT ****/
    }
    listenSockfd = ret;

    retVal = setsockopt( listenSockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof( int ) );
    if ( -1 == ret )
    {
        perror( "Error from setsockopt system call " );
    } else {

        myAddr.sin_family           = AF_INET;
        myAddr.sin_port             = htons( 2014 );
        myAddr.sin_addr.s_addr      = htonl( INADDR_ANY );
        memset( myAddr.sin_zero, 0, 8 * sizeof( char ) );

        retVal = bind( listenSockfd, (struct sockaddr *)&myAddr, sizeof( struct sockaddr ) );
        if ( 0 != ret )
        {
            perror( "Error from bind system call " );
        }
    }

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 01-23-2014 at 12:55 PM.. Reason: code tags to add
# 2  
Old 01-23-2014
Try netstat -an | grep 2014 and see whatever's hogging that address. Just because you're willing to share with it doesn't mean it's willing to share with you...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Socket Programming

HI Can anyone provide me with codes for file transfer server to client or vice versa? Also please explain how to compile those programs in ubuntu terminal as i am totally new to socket programming. Thanks (1 Reply)
Discussion started by: mayhemtrigger
1 Replies

2. Programming

Socket programming

Hi everyone, I'm new to this forum. I'm working on new project for last few days and this forum already helped me on couple of occasions. I don't have any prior experience with network programming so I'll appreciate any advise given. I'm trying to do the following: 1. open user... (2 Replies)
Discussion started by: _thomas
2 Replies

3. Programming

help with socket programming in c

i'm doing a simple program in socket programming on c i have server that can handle 2clients in a single machine i'm running ubuntu linux so i got it work but the probelm when clients send a message the server will echo it but i cant distinguish which client send the message client 1 or client... (7 Replies)
Discussion started by: kedah160
7 Replies

4. UNIX for Dummies Questions & Answers

hi i need help with socket programming

in socket programming how can i : Create for example 3 blank files, namely: server, client, network •Server: act as servers/provider, will receive all requests from different client •Client: requesters •Network: middle-layer of communication between server & client any tips or... (6 Replies)
Discussion started by: kedah160
6 Replies

5. UNIX for Dummies Questions & Answers

Socket programming

in c socket programming, how can I send and received on the same port? (7 Replies)
Discussion started by: Peevish
7 Replies

6. UNIX for Advanced & Expert Users

socket programming

can we send udp message to a destination ip address .. without having an ip address configured in our machine using recvfrom ? (2 Replies)
Discussion started by: Gopi Krishna P
2 Replies

7. Programming

Socket programming

Hello!:) I'm trying to do some socket programming based on the following situation: I have a directory service named Casino that will hold all the information regarding the gamers that will try to connect to it in order to play a game(for example (Blackjack).Once they make the login they are... (4 Replies)
Discussion started by: maracumbigo
4 Replies

8. Programming

Need Help Regarding Socket Programming

Can anyone plz me. I need a sample code for the following description. Its urgent. It is C/Socket program with the following descriptions: NAME coreadServer - Concurrent Readers Server. coreadClient - Concurrent Readers Client. SYNOPSIS coreadServer <OutputFile> coreadClient <n>... (1 Reply)
Discussion started by: priya.vmr
1 Replies

9. Programming

Socket Programming socket

Hello, I actually try to make client-server program. I'm using SCO OpenServer Release 5.0.0 and when I try to compile my code (by TELNET) I've got this error : I'm just using this simple code : and I get the same error if I use : If someone can help me, Thanks (2 Replies)
Discussion started by: soshell
2 Replies

10. Programming

Socket Programming

Dear Reader, Is there any way to check up socket status other than 'netstatus ' Thanks in advance, (1 Reply)
Discussion started by: joseph_shibu
1 Replies
Login or Register to Ask a Question