Click to See Complete Forum and Search --> : Client/Server communication over the internet.
SeanW
May 15th, 2010, 04:33 PM
I have written some programs with both bsd sockets on linux and winsock in windows and have created a few client/server apps that work well. However, these programs only work over the LAN. This leads to my question.
I don't know what I have to learn next to make my server/client programs capable to send and receive data over the internet. Are there tutorials on this?
It seems like a lot of tutorials show how to get a client/server to communicate over LAN, but not the internet.
hoxsiew
May 15th, 2010, 05:29 PM
There's really no difference as far as the client/server is concerned. I suspect that one of the two (client or server) is behind a firewall and thus not visible to the other across the Internet.
SeanW
May 15th, 2010, 09:31 PM
Thanks for replying.
Well it can't be a firewall issue, I am certain. I believe I am doing something wrong in the code.
Here is the portion of my server code where I am filling out the SOCKADDR_IN struct:
SOCKADDR_IN serverInf;
serverInf.sin_family=AF_INET;
serverInf.sin_addr.s_addr=inet_addr("The server remote IP here");
serverInf.sin_port=htons(8888);
if(bind(Socket,(SOCKADDR*)(&serverInf),sizeof(serverInf))==SOCKET_ERROR)
{
std::cout<<"Unable to bind socket.\r\n";
WSACleanup();
system("pause");
return 0;
}
For testing sakes, if I hard-code my remote IP where it says "Remote IP Here", I get a winsock error code 40049 when I try to bind, which states that it cannot assign the requested address. I am definately not getting something critical here. What am I doing wrong? This source works fine for a LAN situation( of course given s_addr is given a local IP).
hoxsiew
May 15th, 2010, 09:49 PM
serverInf.sin_addr.s_addr should be set to INADDR_ANY to listen on any interface. You can set it to a specific address if you have more than one interface and only want to listen on that interface, but that's rare. You can't bind to an address that is on the server machine.
henky@nok.co.id
June 2nd, 2010, 10:58 AM
You can't bind to an address that is on the server machine.
As far as i know that binding to IP address of server machine where program is running is available.
From TCP/IP network programming perspective, there is no difference between LAN and Internet environment.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.