Hello all creating a network lobby for a game. So far what i have is a server and a client program, the clients can connect to the the server and talk to each other via the server. I am doing this through TCP and using asynchronous socks ( WSAAsyncSelect () ) (using c++ btw)
Im now trying to get the client program to host a room which involves them binding to a port and accpeting connections whilst still connect to the server. Other clients will be able to connect to them and still also connected to the server. Both clients in the hosted room and host will DC from the server when the game begins. (when the client is hosting or a client is connecting to the hosting client the socks are set to asynchronous mode after they have connected or after they have bound and listened)
What my problem is that when a client hosts and binds to a port and when another client connects (hosting client can have up to 8 connections) to the hosting client. The asynchronous sock does not seem to pick them up, i have put a printf's in the FD_ACCEPT bit for the hosting client and a printf for in the FD_CONNECT bit for the connecting client none of these printf show up after a client "connects" to the hosting client.
What i have done is the following i added two new extra flags for hosting client and the client joning the host.
// flag for connection to server
#define WM_WSASERVCONNECASYNC (WM_USER +2)
// flag for hosting client to recive connection form peers
#define WM_WSAHOSTINGCONNECASYNC (WM_USER +300)
// flag for connection to the hosting peer
#define WM_WSACONNECTOHOSTASYNC (WM_USER +400)
In the main.cpp I create the class instances for the connection to the server socket, connetion to the host client socket, a socket for when they are hosting, and a array instance socket for the peers when the client is hosting.
CWinSockObject ServerConnectionSoc; // socket to connect to the server
CWinSockObject ConnectionToHostSoc; // socket to conect to the hosting peer
CWinSockObject HostingConnectionSoc; // sock for the hosting peer.
// sock for the connecting peers
CWinSockObject HostPeerConnectionSoc[MAX_HOSTPEERS];
then in the dialog prodcedure function i done this.....
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_WSACONNECTOHOSTASYNC:
if (WSAGETSELECTERROR(lParam))
{
// pfrintf error
}
switch (WSAGETSELECTEVENT(lParam))
{
case FD_READ:
break;
case FD_CONNECT:
// printf connected to host
break;
case FD_CLOSE:
// printf connection lost from host
break;
}
break;
case WM_WSAHOSTINGCONNECASYNC:
if (WSAGETSELECTERROR(lParam))
{
// pfrintf error
}
switch (WSAGETSELECTEVENT(lParam))
{
case FD_READ:
break;
case FD_ACCEPT:
// printf some 1 has connected
break;
case FD_CLOSE:
// printf connection lost
break;
}
break;
case WM_WSASERVCONNECASYNC:
if (WSAGETSELECTERROR(lParam))
{
}
switch (WSAGETSELECTEVENT(lParam))
{
case FD_READ:
// printf recived data from server
break;
case FD_CONNECT:
// connected to server
break;
case FD_CLOSE:
// lost connection to server
break;
}break;
}
}
In win main.....
When the user is connecting to the server they will connect using the servers ip address and tcp port number and set the socket to async mode. this works fine
If the client is hosting they will bind to a port, call the listen function then set that socket to async mode. In FD_ACCEPT under WM_WSAHOSTINGCONNECASYNC they will accept any connection requests.
If the client is connecting to the hosting peer they will connect to the hosting peers ip address and tcp port then set the port to async mode.
What i am i doing wrong ? hope i have explained the problem well