java.net.ConnectException: Connection refused: connect

Hello, i'm writing a client to client application with tcp. my app works fine if i just send some strings, but when i try to send/receive a file to the/from the other person i'm testing with, i get this exception, could it be that he can't receive files because his connection is behind a NAT? but why does he do receive string messages then?

here's the stacktrace

java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(Unknown Source)

at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.<init>(Unknown Source)

at java.net.Socket.<init>(Unknown Source)

at IOClient.ReceiveFile.run(ReceiveFile.java:34)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

java.lang.NullPointerException

at IOClient.ReceiveFile.run(ReceiveFile.java:55)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

(ReceiveFile.java:34)

this is when i create a socket to receive the data like this: transfer =new Socket(myIp,4322);

(for the moment a statis port but it will become dynamic)

(ReceiveFile.java:55)

is when i try to close the socket, but this gives a nullpointer because there isn't a connection established on that socket yes?

[2686 byte] By [Boerkuuuhha] at [2007-11-26 12:22:05]
# 1
There isn't any essential difference between file and string in the case. If you can send some strings without refused, you must can send some files.Message was edited by: john60
john60a at 2007-7-7 15:14:47 > top of Java-index,Archived Forums,Socket Programming...
# 2
> java.lang.NullPointerException> at IOClient.ReceiveFile.run(ReceiveFile.java:55)Isn't that a great hint that you have a bug at line 55 in ReceiveFile.java, where you are attempting to de-reference a null object reference?
warnerjaa at 2007-7-7 15:14:47 > top of Java-index,Archived Forums,Socket Programming...
# 3
this is when i create a socket to receive the data like this: transfer =new Socket(myIp,4322);> (for the moment a statis port but it will become dynamic)Does other client application monitor the socket in the same port after changing dynamically?
harishotya at 2007-7-7 15:14:47 > top of Java-index,Archived Forums,Socket Programming...
# 4

yes, both send and receive threads use the same port number

can it give problems if i create 2 server sockets on the same computer?

is it ok to use

sendSocket= new ServerSocket(4322);

transfer = sendSocket.accept();

in the send thread, or do i have to create first the serversocket, and after this create a thread for "transfer" so serversocket won't be declared in the thread itself?

Boerkuuuhha at 2007-7-7 15:14:47 > top of Java-index,Archived Forums,Socket Programming...
# 5
> can it give problems if i create 2 server sockets on> the same computer?Not if they have different port numbers, but why do you need two?
ejpa at 2007-7-7 15:14:47 > top of Java-index,Archived Forums,Socket Programming...