CyanPrime
|
 |
«
Posted
2012-07-12 21:55:27 » |
|
Alright, so I've got my port forwarded, and I've tried it with all firewalls off, and in DMZ mode (All ports open), so It's not a network problem. I've scanned my port with the server running, and the scanner picks up the port, and the server (Thinking it's a player) prints out that a new player has connected. The client can connect to the server on localhost, and 127.0.0.1, but not on any global IP. I've tried this on multiple networks (Giving friends the server, and client) but to no avail. So I'm going to post some connection code up, and maybe one of you can tell me whats wrong? Also I'll post up the client/server pack, in hopes that one of you can get it working, somehow. Anyway, this really was my last place to ask for help, but I've tried this for 2 days now, and asked on SO and the game dev community I frequent. Also, no, I'm only getting a timeout exception on the client after a little while, no other exceptions. 1 2 3 4 5 6 7
| try { String ip = JOptionPane.showInputDialog("Please input a IP address"); String port = JOptionPane.showInputDialog("Please input a open port number"); mySocket = new Socket(ip, Integer.valueOf(port).intValue()); fromServer = mySocket.getInputStream(); toServer = mySocket.getOutputStream(); } catch (Exception e) { e.printStackTrace(); } |
Edit: forgot the link: https://dl.dropbox.com/u/28109593/cybatar-test.zip
|
|
|
|
|
sproingie
|
 |
«
Reply #1 - Posted
2012-07-12 22:03:21 » |
|
What's your listener code look like?
|
|
|
|
|
CyanPrime
|
 |
«
Reply #2 - Posted
2012-07-12 22:07:08 » |
|
What's your listener code look like?
for the server? Well, I already know it's not a server problem, but no harm in showing it off, I guess. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| try { final ServerSocket serverSocket = new ServerSocket(Integer.valueOf(JOptionPane.showInputDialog("Please input a open port number")).intValue());
while(!stopServer){ if(waitForPlayers){ Socket clientSocket = null; try { clientSocket = serverSocket.accept(); } catch (IOException e) { e.printStackTrace(); } playerID++; playersConnected.add(new Player(playerID)); new PlayerThread(playerID, this, mainText, playerID, clientSocket).start(); mainText.append("Player " + playerID + " connected!"); }
else{ for(int i = 0; i < playersConnected.size(); i++){ playersConnected.get(i).update(); } }
Thread.yield(); } } catch (Exception e) { e.printStackTrace(); } |
And here is the send/receive code in PlayerThread: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| me = parent.playersConnected.get(myPlayer); try { if(mySocket.isConnected()){ int psize = (packetSize * (byte) parent.playersConnected.size()) + 7; ByteBuffer bb = BufferUtils.createByteBuffer(psize); bb.put((byte) 50); bb.put((byte) 100); bb.put((byte) 60); bb.put((byte) 90); bb.put((byte) parent.playersConnected.size()); bb.put(flag); bb.put(me.id);
for(int i = 0; i < parent.playersConnected.size(); i++){ bb.put(parent.playersConnected.get(i).id); bb.put(parent.playersConnected.get(i).state); bb.putFloat(parent.playersConnected.get(i).pos.x); bb.putFloat(parent.playersConnected.get(i).pos.y); } bb.flip();
byte[] bytesToSend = new byte[psize]; bb.get(bytesToSend, 0, bytesToSend.length);
toPlayer = mySocket.getOutputStream(); toPlayer.write(bytesToSend); toPlayer.flush();
byte[] recievedBytes = new byte[2]; fromPlayer = mySocket.getInputStream();
fromPlayer.read(recievedBytes);
if(recievedBytes != null){ mainText.append("playerID: " + recievedBytes[0] + " state:" + recievedBytes[1] + "\n"); if(recievedBytes[0] == me.id) me.state = recievedBytes[1]; } me.update();
}
Thread.sleep(60); } catch (Exception e) { die = true; e.printStackTrace(); } |
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
sproingie
|
 |
«
Reply #3 - Posted
2012-07-12 22:36:01 » |
|
I was interested in how you were binding the server socket. The one-arg constructor for ServerSocket should definitely be binding to 0.0.0.0, so that's not the problem. Just for grins, what does System.out.println(serverSocket.getLocalSocketAddress()) show?
Are you able to connect to the server on its non-localhost address on that machine itself? If it's NAT'ed, i mean the internal one like 192.168.x.x or 10.x.x.x
|
|
|
|
|
CyanPrime
|
 |
«
Reply #4 - Posted
2012-07-12 22:43:05 » |
|
I was interested in how you were binding the server socket. The one-arg constructor for ServerSocket should definitely be binding to 0.0.0.0, so that's not the problem. Just for grins, what does System.out.println(serverSocket.getLocalSocketAddress()) show?
Are you able to connect to the server on its non-localhost address on that machine itself? If it's NAT'ed, i mean the internal one like 192.168.x.x or 10.x.x.x
Good question about the local IP thing. Yes, it does connect to my 10.x.x.x IP (10.0.0.4) And the system.out.println gave me "0.0.0.0/0.0.0.0:44444" <--- that.
|
|
|
|
|
sproingie
|
 |
«
Reply #5 - Posted
2012-07-12 22:57:51 » |
|
Sounds like the problem is somewhere on the network, perhaps with your port forwarding. Worst case is, your ISP is blocking it. If you want to PM me the public IP I can try hitting it from a couple of my addresses.
|
|
|
|
|
|
|
sproingie
|
 |
«
Reply #7 - Posted
2012-07-12 23:03:20 » |
|
Good thinking -- I'm so used to popping over to my AWS box for an outside connection that I forget about the webby web 
|
|
|
|
|
CyanPrime
|
 |
«
Reply #8 - Posted
2012-07-12 23:03:51 » |
|
Success: I can see your service on 67.160.14.227 on port (44444) Your ISP is not blocking port 44444 from ra4king's suggested site.
|
|
|
|
|
ra4king
|
 |
«
Reply #9 - Posted
2012-07-12 23:06:21 » |
|
Ok so your router is port forwarding correctly to your computer, and your computer's firewall has the port open so far.
Are you using that IP address to connect?
|
|
|
|
Games published by our own members! Check 'em out!
|
|
CyanPrime
|
 |
«
Reply #10 - Posted
2012-07-12 23:07:11 » |
|
I've already tried to connect with both the PC and router firewall turned off, and in DMZ mode (All ports open). All failed.
|
|
|
|
|
CyanPrime
|
 |
«
Reply #11 - Posted
2012-07-12 23:07:37 » |
|
Sounds like the problem is somewhere on the network, perhaps with your port forwarding. Worst case is, your ISP is blocking it. If you want to PM me the public IP I can try hitting it from a couple of my addresses.
PMed you.
|
|
|
|
|
CyanPrime
|
 |
«
Reply #12 - Posted
2012-07-12 23:08:55 » |
|
Are you using that IP address to connect?
If by "that" you mean the same one I'm getting off the site, then yes.
|
|
|
|
|
ra4king
|
 |
«
Reply #13 - Posted
2012-07-12 23:12:52 » |
|
I don't see what else could be done here. You use ServerSocket with the int parameter, giving it 44444. Your router port-forwards 44444 to your internal IP address. Your firewall has port 44444 open. Connecting to localhost on port 44444 works. Connecting to your public IP address on port 44444 fails.
Have you tried connecting to your private IP address?
|
|
|
|
CyanPrime
|
 |
«
Reply #14 - Posted
2012-07-12 23:15:04 » |
|
I don't see what else could be done here. You use ServerSocket with the int parameter, giving it 44444. Your router port-forwards 44444 to your internal IP address. Your firewall has port 44444 open. Connecting to localhost on port 44444 works. Connecting to your public IP address on port 44444 fails.
Have you tried connecting to your private IP address?
Yes, connecting to local host, 127.0.0.1 or 10.0.0.4 (my lan address) works perfectly.
|
|
|
|
|
ra4king
|
 |
«
Reply #15 - Posted
2012-07-12 23:20:52 » |
|
localhost doesn't prove anything, your LAN address proves your firewall has the port open. So I'm blaming either your router or you.
|
|
|
|
CyanPrime
|
 |
«
Reply #16 - Posted
2012-07-13 03:58:58 » |
|
Tried: 1 2 3 4 5 6 7
| InetAddress addr = InetAddress.getByName(ip); SocketAddress remote = new InetSocketAddress(addr, 44444); SocketChannel mySocketChannel = SocketChannel.open(); mySocketChannel.connect(remote); System.out.println("doesn't get here"); mySocket = mySocketChannel.socket(); |
As you can see it stalls on connect, and doesn't connect to anything.
|
|
|
|
|
sproingie
|
 |
«
Reply #17 - Posted
2012-07-13 04:55:21 » |
|
This isn't a problem with java code. I cannot telnet to that port. Your network is the problem, full stop.
|
|
|
|
|
CyanPrime
|
 |
«
Reply #18 - Posted
2012-07-13 05:36:53 » |
|
Okay, so if you can't telnet, but port scanning sites can connect to it (and the server) what does that mean? Also, friends who have ran the client and server themselves have the same problem. I'm sure not all of them have problem networks.
So any diagnoses?
|
|
|
|
|
ra4king
|
 |
«
Reply #19 - Posted
2012-07-13 05:54:31 » |
|
Double check the router and your computer's firewall.
|
|
|
|
Riven
|
 |
«
Reply #20 - Posted
2012-07-13 05:59:51 » |
|
Portforwarding on a router is for some reason a very brittle technology. I've had about 8 routers, and they all had nice web-interfaces that allowed you to setup portforwarding. Two of those eight actually managed to forward traffic...
You're better off renting a cheap VPS with little to no RAM, and using it solely to setup a reverse (SSH) tunnel: your desktop will connect to the VPS using TCP, and the outbound connection is used to pump traffic from the outside world to your desktop.
|
|
|
|
CyanPrime
|
 |
«
Reply #21 - Posted
2012-07-13 06:04:16 » |
|
Strange, when I disable port forwarding I get a connection refused with the client right away. Why doesn't it do that with port forwarding on? It's not connecting to the server  .
|
|
|
|
|
Riven
|
 |
«
Reply #22 - Posted
2012-07-13 06:05:37 » |
|
Strange, when I disable port forwarding I get a connection refused with the client right away. Why doesn't it do that with port forwarding on? It's not connecting to the server  . probably a firewall in between, or you picked the wrong local IP, or made any other mistake in the config. it's hard to diagnose without information. the serversocket might be listening on 127.0.0.1 instead of your LAN IP. what about specifying the local IP: new ServerSocket(InetAddress.getByAddress("10.0.0.x"), 50, 44444)
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #23 - Posted
2012-07-13 06:14:02 » |
|
I've had experiences like this with setting up a Minecraft server and I heard that you can't connect to your global IP from your own router. Because technically, the router is sending the data to itself
What I think you need to do is get a friend to try and connect and see if it works for the reason above
Someone correct me if I'm wrong.
|
|
|
|
CyanPrime
|
 |
«
Reply #24 - Posted
2012-07-13 06:15:58 » |
|
probably a firewall in between, or you picked the wrong local IP, or made any other mistake in the config. it's hard to diagnose without information. the serversocket might be listening on 127.0.0.1 instead of your LAN IP.
what about specifying the local IP: new ServerSocket(InetAddress.getByAddress("10.0.0.x"), 50, 44444)
Alright, I tried the normal code, then 1
| new ServerSocket(InetAddress.getByAddress("10.0.0.x"), 50, 44444) |
. Both after turning off windows defender, all firewalls (router, and PC) and putting the router into all ports open mode. Same results. With port forwarding enabled I got a timeout after some time, and without port forwarding I got connection refused. Thank you though, that was a good idea. 
|
|
|
|
|
Riven
|
 |
«
Reply #25 - Posted
2012-07-13 06:16:09 » |
|
@HeroesGraveDev sproingie already make an attempt from another machine
|
|
|
|
|
|
HeroesGraveDev
|
 |
«
Reply #27 - Posted
2012-07-13 12:56:20 » |
|
@HeroesGraveDev sproingie already make an attempt from another machine
Didn't see that. Just checking it wasn't a facepalm-level failure
|
|
|
|
ra4king
|
 |
«
Reply #28 - Posted
2012-07-13 19:09:09 » |
|
CyanPrime, did you literally use 'x' in your code for that LAN IP address? You are supposed to replace it with the actual value. I'm just checking for all possibilities here 
|
|
|
|
CyanPrime
|
 |
«
Reply #29 - Posted
2012-07-13 19:29:39 » |
|
CyanPrime, did you literally use 'x' in your code for that LAN IP address? You are supposed to replace it with the actual value. I'm just checking for all possibilities here  Had I done that I would have gotten a error, right? 
|
|
|
|
|
|