wood burning stoves 2.0
The moose likes Sockets and Internet Protocols and the fly likes Simple problem in running a Server class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Simple problem in running a Server class" Watch "Simple problem in running a Server class" New topic

Simple problem in running a Server class

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

I've developed a client/server application to send datagram packets and receive them through the UDP protocol using two classes
this is the Server class

this is the Client class

The problem is that when i try to run the server class from the command prompt :
javac Server.java
// this works well but when i try to run it using this command:
java Server
//it throws this exception:
Exception in thread "main" java.net.SocketException: Unrecognized Windows Sockets error: 0: Cannot bind
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
at java.net.DatagramSocket.bind(DatagramSocket.java:368)
at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
at java.net.DatagramSocket.<init>(DatagramSocket.java:234)
at Server.main(Server.java:8)

How can i get rid of this problem?
thanks in advance

I Hear I Forget, I See I Remember, I Do I Understand.
Tom Reilly

Joined: Jun 01, 2010
Posts: 618
I Googled the error and a couple of items suggested that the port is already in use. I noticed that your server loops forever and does not clean up after itself (by calling DatagramSocket.close). Could it be that another instance is already running? Or maybe not cleaning up caused the port to remain open? Or perhaps another application is using that port? Try using another port or rebooting to close the existing port (both easy tests).

I tried running your server and got a different error (Address already in use) when I tried running it a second time but I'm not running on Windows.
Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

Thanks tom , this is already the case
I've reboot it and it it works well
I agree. Here's the link: http://aspose.com/file-tools
subject: Simple problem in running a Server class
It's not a secret anymore!