• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Exception in thread "main" java.net.BindException: Address already in use: bind

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone!

I ran into a problem yet again, and for the life of me I can not figure out how to solve it.

What I'm trying to do now is set up a server-client communication using udp, but I get this message all the time: Exception in thread "main" java.net.BindException: Address already in use: bind

This is what my server code looks like:



And this is what my client code looks like:




So by running the server code first, and the client code after, I should get the message "Hello" on the console, but I just get an error message.

I've read that this error message means that the particular port is already in use, but I've tried a hundred other ports, and nothing seems to work. Few days ago, I had no problem with this, and the codes above are exactly how my professor's codes look like so I really don't know what goes wrong..

Thank you for your help in advance.

 
Marshal
Posts: 3457
493
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have both the sender and receiver trying to bind to the same port.

Try setting the port in the sender to something different (for example:1235), or even better, don't specify a port at all, and have a random available port be allocated for you:
    DatagramSocket s = new DatagramSocket();
 
Ron McLeod
Marshal
Posts: 3457
493
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, if you are curious, you can see which port was allocated - it is visible at both sender and receiver:

 
greg mic
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:You have both the sender and receiver trying to bind to the same port.

Try setting the port in the sender to something different (for example:1235), or even better, don't specify a port at all, and have a random available port be allocated for you:
    DatagramSocket s = new DatagramSocket();



Thanks a lot Ron!!

Not specifying a port did solve the issue!
 
I found some pretty shells, some sea glass and this lovely tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic