Socket Programming over the Internet
I wrote a simple chat program which perfectly runs on the local host. But, when the client tries to connect to the server via the Internet using the public IP and the port 9999, it does not work as it did on LAN.
As many people have suggested, I did Port-Forwarding as shown in the following figure.
http://www.mediafire.com/conv/0dc403...84a5cab86g.jpg
After configuring Port-Forwarding this website indicates that port 9999 remains open for the specific public IP (I run the server on 192.168.1.100 on private network). Although the port remains open, the client cannot connect to the server. Then I disabled the Windows firewall and tried the same process. But the problem still persists.
Please can someone tell me how can I solve this problem..?
Thanks in advance
Sorry for my bad English
Here is the code of the Chat application..
Server:
Client:
Re: Socket Programming over the Internet
Quote:
Originally Posted by
Laura2
I wrote a simple chat program which perfectly runs on the local host.
What did you mean my friend..?
Re: Socket Programming over the Internet
Never mind. That was a spammer. Using AI stuff to copy posts, and it copied your first line, and post semi-relevant stuff, along with possibly links or stuff. That user has been banned.
Anyway, I wasn't aware that ports could be negative.
It looked like you said port -9999.
Perhaps the app isn't granted admin permission on that network.
Your server is the one online, right? Perhaps a possibility is that it's looking for port -9999 or 9999 on its own network, not yours.
Re: Socket Programming over the Internet
Quote:
Originally Posted by
javapenguin
Never mind. That was a spammer. Using AI stuff to copy posts, and it copied your first line, and post semi-relevant stuff, along with possibly links or stuff. That user has been banned.
Anyway, I wasn't aware that ports could be negative.
It looked like you said port -9999.
Perhaps the app isn't granted admin permission on that network.
Your server is the one online, right? Perhaps a possibility is that it's looking for port -9999 or 9999 on its own network, not yours.
I think you have misunderstood that I had used -9999 (a negative port). As you said I too wasn't aware that a port could be negative.
As shown in the source code I have used port 9999 for my chat application.
According to my app, the server is the one who remains online and listening to the port 9999. When a client tries to connect to the specific public IP of the server through port 9999, the server accepts the connection and grants the particular service to the client.
After configuring Port-Forwarding this website indicates that port 9999 remains open for the specific public IP where the server listens to the specific port. Although the port remains open, the client cannot connect to the server.
In such a situation how can I create a connections among clients and the server..?
Re: Socket Programming over the Internet
djmaxtor
I suppose this IP "112.134.190.41" is the given IP of your provider. What I see in your client program is a "hardwired" code s=new Socket("112.134.190.41",9999);. 2 Questions:
Is this IP static or dynamic?
How you configure your router (i.e. gateway to the web) and your local computer?
By the way, it's better to code Socket s=ss.accept(); than Socket s; ....s=ss.accept(); Reason is that your server can accept MORE incoming requests and only 1 is available and is probably still occupied...
Re: Socket Programming over the Internet
Quote:
Originally Posted by
Voodoo
djmaxtor
I suppose this IP "112.134.190.41" is the given IP of your provider. What I see in your client program is a "hardwired" code s=new Socket("112.134.190.41",9999);. 2 Questions:
Is this IP static or dynamic?
How you configure your router (i.e. gateway to the web) and your local computer?
By the way, it's better to code Socket s=ss.accept(); than Socket s; ....s=ss.accept(); Reason is that your server can accept MORE incoming requests and only 1 is available and is probably still occupied...
Thank you so much for your reply my friend,
The given IP is an Dynamic IP. Since I'm not good in Networking, as I know the assigned IP address remain unchanged until I restart my router. So I just need to check whether I can connect two or more socket applications over the internet.
When configuring my router I followed the following procedure
Login to my router configuration page--> Advanced Setup-->NAT-->Virtual Server Setup--> Then entered the information as follows
http://www.mediafire.com/conv/0dc403...84a5cab86g.jpg
Then I added an inbound and outbound rule for port 9999 in windows firewall.
Can you please help me to sort out this problem? So that I can continue my project work without any doubts.
Thanks in advance
Re: Socket Programming over the Internet
djmaxtor,
it's a very complicated matter. It depends fully on your Router. Because I don't know your Router so recommend you to look at the manuals or ask its tech.support. Normally you have to forward the port and it depends on the feature of your router. Here is the Port Forwarding Guides Listed by Manufacturer and Model - PortForward.com
Your codes are fine. Now it depends only on the Port-Forwarding. Good luck!