scorrpeio
Full Member level 5
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;
}
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;
}