java - TCPConnection refusing connection -
i have standard client/server model , server binds client can not connect , keeps saying connection has been refused. (stacktrace above client code)
i have put computer on dmz ports , open have disabled firewalls.
the following code works fine on localhost , local network address not external ip
for instance serverip string 0.0.0.0 in reality real ip address.
canyouseeme.org success: can see service on 0.0.0.0 on port (25565) isp not blocking port 25565 succeeds when server running
edit: added line of code server see sending data , if being received.
when canyouseeme.org pings 25565 sends null data gives me ip address sent correct pointing towards client error
client stacktrace
java.net.connectexception: connection refused: connect @ java.net.dualstackplainsocketimpl.connect0(native method) @ java.net.dualstackplainsocketimpl.socketconnect(unknown source) @ java.net.abstractplainsocketimpl.doconnect(unknown source) @ java.net.abstractplainsocketimpl.connecttoaddress(unknown source) @ java.net.abstractplainsocketimpl.connect(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.<init>(unknown source) @ java.net.socket.<init>(unknown source) @ main.client.run(client.java:29) @ java.lang.thread.run(unknown source)
client code
synchronized (runner) { while (true) { string sentence; string modifiedsentence; try { bufferedreader infromuser = new bufferedreader(new inputstreamreader(system.in)); /*line 29:*/ socket clientsocket = new socket(serverip, 25565); dataoutputstream outtoserver = new dataoutputstream(clientsocket.getoutputstream()); bufferedreader infromserver = new bufferedreader(new inputstreamreader(clientsocket.getinputstream())); sentence = infromuser.readline(); outtoserver.writebytes(sentence + '\n'); modifiedsentence = infromserver.readline(); system.out.println("from server: " + modifiedsentence); clientsocket.close(); } catch (ioexception e) { e.printstacktrace(); } } }
server code
synchronized (runner) { while (true) { string clientsentence; string capitalizedsentence; serversocket welcomesocket = null; try { welcomesocket = new serversocket(25565); while (true) { socket connectionsocket = welcomesocket.accept(); bufferedreader infromclient = new bufferedreader(new inputstreamreader(connectionsocket.getinputstream())); dataoutputstream outtoclient = new dataoutputstream(connectionsocket.getoutputstream()); clientsentence = infromclient.readline(); if(clientsentence == null) clientsentence = "recieved null packet"; clientsentence = connectionsocket.getinetaddress().gethostaddress().replace("/", "") + " " + clientsentence; system.out.println("received: " + clientsentence); capitalizedsentence = clientsentence.touppercase() + '\n'; outtoclient.writebytes(capitalizedsentence); } } catch (exception e) { e.printstacktrace(); try { welcomesocket.close(); } catch (ioexception e1) { e1.printstacktrace(); } } } }
Comments
Post a Comment