Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

socket creation

0 views
Skip to first unread message

hilz

unread,
Sep 29, 2004, 2:24:44 AM9/29/04
to
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


andreas

unread,
Sep 29, 2004, 2:30:39 AM9/29/04
to

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

andreas


Gordon Beaton

unread,
Sep 29, 2004, 2:34:05 AM9/29/04
to
On Wed, 29 Sep 2004 06:24:44 GMT, hilz wrote:
> 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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

hilz

unread,
Sep 29, 2004, 2:43:12 AM9/29/04
to
never mind....
i was using the wrong method.

appologies!

there is nothing here to see!
move along!


0 new messages