Okay, I've done the same thing to the client program, and I am getting an error at the client's connect() function. I'm guessing it's not the call to connect() itself, so I'll just post all the code.
Code:
#include <iostream>
#include <windows.h>
#include <WINSOCK2.h>
int main( void )
{
WSADATA bWsaDat;
SOCKET bSocket;
SOCKADDR_IN bSockAddr;
HOSTENT *bHost;
char bSendMe[] = "Awesome, I sent!", bServer[] = "localhost";
char bRecieveMe[50];
int bRetVal = SOCKET_ERROR;
if( WSAStartup( MAKEWORD( 2, 0 ), &bWsaDat ) != 0 )
{
std::cout << "WSA initialization failed!" << std::endl;
}
bSocket = ( AF_INET, SOCK_STREAM, 0 );
if( bSocket == INVALID_SOCKET )
{
std::cout << "Failed to create socket!" << std::endl;
}
std::cout << "Waiting for host..." << std::endl;
while( bHost == NULL )
{
bHost = gethostbyname( bServer );
if( bHost != NULL )
{
break;
}
}
bSockAddr.sin_port = htons( 50 ); //I've added it here...
bSockAddr.sin_family = AF_INET;
bSockAddr.sin_addr.s_addr = *( unsigned long* ) bHost->h_addr;
if( connect( bSocket, ( SOCKADDR* )( &bSockAddr ), sizeof( bSockAddr ) ) != 0 )
{
std::cout << "Failed to establish connection with server!" << std::endl;
}
while( bRetVal == SOCKET_ERROR )
{
bRetVal = send( bSocket, bSendMe, strlen( bSendMe ) + 1, 0 );
if( bRetVal == 0 || bRetVal == WSAECONNRESET )
{
std::cout << "Connection closed at other end!" << std::endl;
break;
}
}
bRetVal = SOCKET_ERROR;
while( bRetVal == SOCKET_ERROR )
{
bRetVal = recv( bSocket, bRecieveMe, 50, 0 );
if( bRetVal == 0 || bRetVal == WSAECONNRESET )
{
std::cout << "Connection closed at other end!" << std::endl;
break;
}
}
std::cout << bRecieveMe << std::endl;
closesocket( bSocket );
WSACleanup();
std::cin.get();
return 0;
}
Thanks, and all the variables have b infront of them because I thought it caused the first error
- SirCrono6
Edit: Maybe it's not that, because now the server is failing to bind() again