I made this program:
http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
And it works perfectly if I put the server's hostname as 127.0.0.1 or my computers name (Ajay-PC).
However these 2 methods are LAN or local only not internet. So I changed it to my internet ip. 70.128.xxx.xxx etc. But it didn't work. I checked:
canyouseeme.org
and it said 4444 was CLOSED.
So I did a quick port forward.
Portforward:
Name: My Java Program
Start Port: 4444
End Port: 4444
Server IP: 10.0.0.12 <-- (Yeah this is my Local IP I checked)
then I tried
canyouseeme.org
AGAIN:
and it said 4444 was OPEN
I ran my server client program and it yet to work.
So my problem is the client server program is not working on the internet just locally. So something is blocking it and I don't know what.
EDIT: It's not blocked because as I checked the port is open. But I am recieveing a IO exception not a UnknownHost
Computer:
Windows Vista x64
Norton AntiVirus 2010
Thanks! I'll give best answer or whatever to who ever answers the best ;) :)
How do you have access to the internet? Maybe you have to configure your ADSL modem or your router/switch to forward the port 4444 to your computer.
I guess you are in the LAN if you are using a router connecting to your modem. And your computer connect to the router.
Try to connect to your modem which has your internet IP.
Have you checked that the client is connecting to port 4444 and your public IP? This is another common mistake most people make. If your port is open as you say above and the firewall is off, then there's nothing stopping you connecting.
Use Wireshark or WinDump to snoop the initial TCP handshake. Filter for packets with port 4444. Verify that the opening SYN packet is leaving your computer, that the opening SYN packet is returning to your computer, and to see what whether/how computer is responding to the opening SYN packet.
Note: if you experiment with these tools, you won't be able to use it trace if you use the localhost (127.0.0.1) and your PC IP (10.0.0.12) addresses - in these cases, the packets don't actually leave the computer and can't be snooped. Put the client and server on separate computers if you want to snoop packets on the LAN without involving the gateway.
Related
Could anyone please help me with steps how to verify if port is open/available to use.
Basically we have to verify in one of our server (windows) that
7200 port is open for use.
we have one deployment coming up, and team have end point like htts://servername::7200/index.html
If you are trying to use TCP(Transmission Control Protocol) port then run the telnet host port and see the result
connection refused means that nothing is running on that port
accepted means that something is running on that port
timeout means that a firewall is blocking access
In accordance to example in this link:
http://www.javatpoint.com/socket-programming
As i understand port no :6666 is an imaginary or raw port used to illustrate socket programming. I want to know how the PC knows that it has server with port 6666 after running both myClient.java and myServer.java.
Also I want to know while doing Real socket programming the myServer.java needs to be placed in real server location if not then where ? just want to understand where to initialize a serverSocket class object! In server side or in client side ?
Also how Operating system or PC(in general ) search for available ports ?
Your linked document is broken, nevertheless, let me explain a bit how the network sockets work.
A computer has multiple network interfaces. If you're running window you can check them by running ipconfig /all, on linux/osx with ifconfig. You'll see that you have a loopback interface with IP address 127.0.0.1. Also, by convenience it was decided to add a "name" to this loopback interface, and it'd be localhost. You can verify this in /etc/hosts file where a mapping between 127.0.0.1 and localhost exists.
Saying that, a computer can find a route to localhost on himself using the system kernel. This loopback interface is virtual, implemented in the operating system so no packets will go through your Ethernet interface or wifi card.
TCP and UDP are protocols used on top of IP to send data. TCP establishes a connection via the 3-way handshake and packet reception is acknowledged by the server. UDP is non-connection oriented, so a client will send packets to the ports and no acknowledges are sent. That's just a huge summary.
When you want to listen on a port, your application needs to actually tell it to the operating system and when the networking component of the OS receives some packets with the TCP.dst value equal to 6666 (in your case) it will send the payload to your application. The OS is responsible for acknowledging the packets and all the underlaying communication which is transparent from you.
As you might guess, the operating system can only bind the same port port to a single application. That's why if you start twice a web server, the second execution will fail.
You can check which ports are listening with netstat -l on a linux machine.
I have developed a Chat Application for two person, one being server another will be client, using Java Socket Programming. Every thing was fine till this morning. It was working over localhost, local networks as well as On my DDNS ( My Router is configured to forward any traffic on it's port 8888 and 3434 to same port on my IP, which is again Reserved in my router ). But now it works strangely. I ran a server on my laptop at port 8888 I tried to connect the client through my DDNS on port 8888, Client shows it is connected, but Server shows it is disconnected. Client even sends message successfully which does not appear in server.
I want to know what causes such strange behaviour of my application, is this my firewall, because I have used my DDNS a lot in order to debug some issue.
I also want to know what precautions should one take in order to use DDNS in Java Socket.
Additional Informations:
My DDNS in on Dynu
OS: Windows 7 32 bit
Quick Heal Antivirus and firewall (Outdated)
I am adding some pictures:
Me and my friend are working on online game project and for beginning we use TCP connection made by java. What do I have to do to successfuly make my friends client connect to my server? On local host it works perfectly. What are the reqiurements for this?
Check to make sure that your firewall allows connections from remote hosts to your computer on the port you are hosting the game on. If you friend is connecting to your computer from another location you will most likely need to add a firewall rule to your router.
I am trying to tcp connect to a server machine in java, by using its public i.p. but when i run the client application i constantly getting a connection refused error. if i used localhost instead of the public ip, it works perfectly.
i search the internet for several causes of the issue but i couldnt fix it.
i forwarded the port to my machines' local i.p address(192.168.1.3) in routers settings. then i checked if port is listening when i ran the server application using netstat -an. i saw lines like,
0.0.0.0:19999 or []:19999 .
19999 is the port number i am trying to listen to. Then i changed my ServerSocket constructor to the 3 parameter one, which also binds the local address.
InetAddress miad = InetAddress.getByAddress(addr);
ServerSocket socket1 = new ServerSocket(port,10,miad);
addr is the InetAddress of my machines local i.p. After these modifications, when i start the server application, i run netstat and it shows:
TCP 192.168.1.3:19999 0.0.0.0 LISTENING
Here i think that my server is listening on the port specified properly.
I have also disabled my firewall and antivirus software.
I have seen several threads and discussions on the net about the issue, and tried most of the things mentioned there, but i keep getting the connection refused error.
What can i be doing wrong? It runs without any errors when i test with localhost.
This is because of the router (not very sure, but almost). Try to see if a webservice like www.canyouseeme.org can connect to your server.
The main idea is that an internal machine (inside the LAN) cannot connect to a machine inside the same LAN by using the external (public) IP address.
I'm pretty sure that it will work, using you internal ip (192.168.1.3).
And if you are sure that you forwarded ports correctly, CanYouSeeMe will say your server is reachable. If it doesn't, make sure you ISP isn't blocking the ports for some kind of "safety reasons".
To figure out if your problem relates to Java and programming please do
telnet 192.168.1.3 19999
If it can't connect then superuser.com would be a better place to discuss this issue.