|
-
May 15th, 2010, 04:33 PM
#1
Client/Server communication over the internet.
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.
-
May 15th, 2010, 05:29 PM
#2
Re: Client/Server communication over the internet.
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.
-
May 15th, 2010, 09:31 PM
#3
Re: Client/Server communication over the internet.
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).
-
May 15th, 2010, 09:49 PM
#4
Re: Client/Server communication over the internet.
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.
-
June 2nd, 2010, 10:58 AM
#5
Re: Client/Server communication over the internet.
 Originally Posted by hoxsiew
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.
henky
----------------------------------
[email protected] is not my email address anymore...
Jangan Pernah Menyerah
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|