Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

why Bind( ) function returns the -1

Status
Not open for further replies.

scorrpeio

Full Member level 5
Joined
Dec 26, 2006
Messages
286
Helped
10
Reputation
20
Reaction score
9
Trophy points
1,298
Activity points
3,496
I am currently doing the socket programming for UDP in VC++ using Visual Studio 2005 where, I used the Bind() function to bind the socket. But I everytime gets the result..........Bind failed.
When I checked out, the function Bind() returns -1.
I dont get why this happen?? Please let me know.


// Create A Socket

int ServerSocket;
ServerSocket = socket( PF_INET,SOCK_DGRAM, 0 );

//Check for existance

if ( ServerSocket < 0 )
{
MessageBox ("The Socket is not created!!!" );
}

//Bind the Socket

int MySock;
struct sockaddr_in MyAddr;

MySock = socket ( PF_INET,SOCK_DGRAM, 0 );
MyAddr.sin_family = AF_INET;
MyAddr.sin_addr.s_addr = inet_addr( m_IPAdd );
MyAddr.sin_port = htonl( m_iPortNo );

bind ( ServerSocket, (SOCKADDR*) &MyAddr, sizeof( MyAddr ) );

if ( bind ( ServerSocket, (SOCKADDR*) &MyAddr, sizeof( MyAddr ) ) == SOCKET_ERROR )
{
MessageBox( "bind( ) failed." );
closesocket( ServerSocket );
return;
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top