Home arrow static arrow Java Programming [Archive] - Sharing Ports
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Sharing Ports
This topic has 6 replies on 1 page.

Posts:27
Registered: 7/27/04
Sharing Ports  
Aug 2, 2004 12:50 PM



 
I'M trying to create a program that sends information over the net using datagrams. The only problem is that in each program i create an instance of a DatagramSocket using port 998 but when i run it i get the following error

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

Is their anyway i can share port 998
 

Posts:13,769
Registered: 00-11-29
Re: Sharing Ports  
Aug 2, 2004 12:57 PM (reply 1 of 6)



 
If I'm not mistaken, the OS won't let you use a port that is already in use. The question is, why would you want to? Just use a different port or figure out what is using it and kill it or something.
 

Posts:27
Registered: 7/27/04
Re: Sharing Ports  
Aug 2, 2004 12:59 PM (reply 2 of 6)



 
I wrote two programs one recieves the datagram so it must use socket 998 and the other program sends the sends the info using socket 998. So both of my programs are using the same socket thats why i get the error.
 

Posts:13,769
Registered: 00-11-29
Re: Sharing Ports  
Aug 2, 2004 1:06 PM (reply 3 of 6)



 
Are these programs talking to each other or is there another machine involved?
 

Posts:13,769
Registered: 00-11-29
Re: Sharing Ports  
Aug 2, 2004 1:06 PM (reply 4 of 6)



 
Are these programs talking to each other or is there another machine involved?
 

Posts:3,534
Registered: 9/30/99
Re: Sharing Ports  
Aug 2, 2004 2:08 PM (reply 5 of 6)



 
I wrote two programs one recieves the datagram so it
must use socket 998 and the other program sends the
sends the info using socket 998. So both of my
programs are using the same socket thats why i get the
error.

The solution seems fairly simple then, just create a 3rd program that controls the port and your other 2 programs just talk to the 3rd program. Or turn your "programs" into modules and make a loader for them.
 

Posts:6
Registered: 6/10/03
Re: Sharing Ports  
Aug 3, 2004 6:45 AM (reply 6 of 6)



 
Try using a port number higher than 1024. Most sane operating systems will only allow someone with root/administrator privileges to listen on ports numbered less than 1024. You are ofcourse allowed to open connections to ports numbered below 1024.
 
This topic has 6 replies on 1 page.