socket creation

H

hilz

hi
i am trying to create a socket as follows:

mailSocket = new Socket("localhost",8084); //tried with a lot of other port
numbers too

and i keep getting the exception:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at mail.Server.<init>(Server.java:28)
at mail.Server.main(Server.java:11)



what do i need to do to be able to successfully create a socket?
thanks
hilz
 
A

andreas

i am trying to create a socket as follows:

mailSocket = new Socket("localhost",8084); //tried with a lot of other
port
numbers too

and i keep getting the exception:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.<init>(Socket.java:309)
at java.net.Socket.<init>(Socket.java:124)
at mail.Server.<init>(Server.java:28)
at mail.Server.main(Server.java:11)



what do i need to do to be able to successfully create a socket?
thanks
hilz

you need the port to be open (i.e. a ServerSocket accepting connections on
that port) ....

andreas
 
G

Gordon Beaton

i am trying to create a socket as follows:

mailSocket = new Socket("localhost",8084); //tried with a lot of other port
numbers too

and i keep getting the exception:

java.net.ConnectException: Connection refused: connect
[...]

what do i need to do to be able to successfully create a socket?
thanks

The Socket constructor actually connects to the remote host and port
you specify. If nobody's listening, the constructor will fail as
you've discovered.

Either connect to a well known service (for example port 80 on most
web servers), or write a second program that opens a ServerSocket to
accept incoming connections on a port you've chosen.

/gordon
 
H

hilz

never mind....
i was using the wrong method.

appologies!

there is nothing here to see!
move along!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top