I'm trying to write basic client server. The code works fine when I'm using "localhost" and random port. The problems start when I run the server and the client from different hosts, and then I get "Connection Refused".
I searched for this problem and none of the solutions helped (Disable the firewall, run the server before the client, connection to the internet etc)
Again, the code works fine, my firend ran it and all works fine. The problem is probably with my computer. I have a router.
Thank you
Related
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:
I've implemented a simple ZeroMQ (0MQ) server and client. It works well when I use them on a machine (local). But when I run the client on one another machine, it doesn't work (it cannot connect to the remote server). I've checked my firewall and it's inactive (in Ubuntu 14.04).
My server code written in java is:
ZMQ.Socket responder = context.socket(ZMQ.REP);
responder.bind("tcp://*:5555");
and the client code:
requester.connect("tcp://ipaddress:5555");
in which "ipaddress" is the IP address of my server.
I've tried also different port numbers.
Please, explain what is the problem and what do you suggest to solve the problem??
Thanks in advance
I'm trying to run a small, custom HTTP server embedded in my Android application (to aid in debugging the app). However, I cannot reliably to connect to the HTTP server from my desktop web browser when the server is running on my Android 2.3.4 phone.
I know the HTTP server code works (at least the basics), because one time the connection went through fine. And the code works reliably when run on my desktop (my app is a libgdx-based, pure Java app that can be built for Windows or for Android).
I have the Android permissions correct, because I was getting the PermissionDenied fault (when setting up the socket listener) thrown before I added the android:name="android.permission.INTERNET" permission. The server-side code runs in its own thread and boils down to:
ServerSocket ss = new ServerSocket(serverPort);
Socket clientSocket = ss.accept();
I'm using port 8080. (I tried port 80 but hit the must-be-root-below-port-1024 "feature" of Linux).
The LogCat output looks fine. My app just prints its "listening on port 8080" message and no exceptions seem to be thrown.
Network connectivity seems fine (browsing the internet from the phone is working, and I can ping the phone from desktop). I'm using WiFi, not 3G.
I think I found it. I was missing a call to:
ss.setReuseAddress(true);
after creating the server socket. This means each restart of the app (pause/resume, too) was (silently?) failing to create server socket because the socket was marked as 'in use' for a bit. This explains why it was so unreliable (only the very first run, or running after a long enough wait would work ...)
I found it by staring at the code linked to from this blog entry.
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.
I have this server/client TCP. The server is run off my desktop. And the client is an applet over at http://example.com/new/ (You won't get to it because it will not load...) It WILL load for me but not anyone else.
The port is 24556 and the host is localhost but I DID portforward the port on my linksys admin page so people SHOULD connect. It works for me (obviously) because the server prints out the movement I go... but the applet won't even load for anyone else.... what's the deal?
Is the applet connecting to localhost or to the ip of your router?
I got the applet to load. Not sure why...I can't move around though.
This might have something to do with self signed content. And browsers defaulting to not let users run things. I know I've run into that problem before.
Is your computer set up with a static ip? Make sure the router points to that computer, or it'll never connect.
I wrote up a chat client in Java, see it here: http://code.google.com/p/phroxchat, feel free to use it to check if your port forwarding is setup properly.