winsock connect not working between two different wireless networks

Started by
11 comments, last by Deek880 13 years, 1 month ago

I have set up a basic chat box in which one of my computers acts as a server and the host is the ip address of that computer.
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/


Try port forwarding. or work true a server which patch you true
Advertisement
I used a winsock function called gethostbyname and some other code from dumas book programing winsock and the program insists my computers actual ip is 36.180.20.0. Still not able to connect. The verizon router claims this to be an invalid format. I tried setting this as my static ip address (just for the heck of it since I know its unique) in windows and windows changed the subnet mask to 255.0.0.0.

In any event with my ip address as above pointed to by the client program, I can connect the client to the server but only on the same internet service not across services.

The changes also prevent internet explorer from accessing the internet.


[quote name='Deek880' timestamp='1298429407' post='4777814']
Today that website says my IP address is 64.12.116.78

Yesterday it said my IP address was 64.12.116.9 and on a separate try 205.188.116.78


That IP address is what you need to connect to from the outside. For further information, check out the "how can people find my server" question answers in the FAQ!
[/quote]

I think thats about it. My internet service provider is trying to play me cheap with a bunch of junk that'stopping me from doing my own thing.

[quote name='Deek880' timestamp='1297826946' post='4774793']
I have set up a basic chat box in which one of my computers acts as a server and the host is the ip address of that computer.
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/


Try port forwarding. or work true a server which patch you true
[/quote]

This topic is closed to new replies.

Advertisement