• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Simple problem in running a Server class

 
Ranch Hand
Posts: 82
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks tom , this is already the case
I've reboot it and it it works well
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic