The client can connect to the host on the same computer or between my lap top and my home computer as long as they are
both connected through my verizon wirelss service. As soon as I take my lap top away from home and try to communicate with my running program on my home computer through some other wireless network, the client program can't find the server.
#include <winsock2.h>
#include <windows.h>
#pragma comment(lib,"ws2_32.lib")
#define IDC_EDIT_IN 101
#define IDC_EDIT_OUT 102
#define IDC_MAIN_BUTTON 103
#define WM_SOCKET 104
char *szServer="192.168.0.254";
int nPort=5555;
HWND hEditIn=NULL;
HWND hEditOut=NULL;
HWND ghMainWnd=0;
HINSTANCE ghAppInst = 0;
SOCKET Socket=NULL;
char szHistory[10000];
int gLength=0;
int iIndex=0;
// Set up Winsock
WSADATA WsaDat;
int nResult=WSAStartup(MAKEWORD(2,2),&WsaDat);
if(nResult!=0)
{
MessageBox(hWnd,
"Winsock initialization failed",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(Socket==INVALID_SOCKET)
{
MessageBox(hWnd,
"Socket creation failed",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
nResult=WSAAsyncSelect(Socket,hWnd,WM_SOCKET,(FD_CLOSE|FD_READ));
if(nResult)
{
MessageBox(hWnd,
"WSAAsyncSelect failed",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
// Resolve IP address for hostname
struct hostent *host;
if((host=gethostbyname(szServer))==NULL)
{
MessageBox(hWnd,
"Unable to resolve host name",
"Critical Error",
MB_ICONERROR);
SendMessage(hWnd,WM_DESTROY,NULL,NULL);
break;
}
// Set up our socket address structure
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(nPort);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr=*((unsigned long*)host->h_addr);
connect(Socket,(LPSOCKADDR)(&SockAddr),sizeof(SockAddr));
There are other parts that are left out of course that work as I copied the program primarily from another source. Why would it work when the two programs are connected on the internet and physically close together but not when the two computers are trying to connect from a distance using different internet providers/