I'm trying to create a program that will listen on a port for any packets coming through.. see, this other server program already accesses the same port (to send and receive packets).. I just want to listen to the port for any packets coming into the the other program.. then my program will do some work, but it never sends out through the port.. <p>
I've already written a few port accessing programs.. I did an example HTTPD Server, and UDP Heartbeat & Pulse Server.. so I've got the basics down.. but when I try to access the port in this current program, it gives me the error "Address in use: Cannot bind".. meaning the other server is using it, but I'm just interested in "listening" to the port, thats all.. is there some other way around this problem?.. this is what I have so far.. it just listens on the port and outputs any data that comes in (in theory)..<p>
import java.net.*;<br>
import java.io.*;<br>
import java.util.*;<p>
public class QStats {<p>
public static void main( String [] argv ) throws IOException {<p>
DatagramSocket s = new DatagramSocket( Integer.parseInt( argv[0] ) );<p>
while( true ) {<br>
DatagramPacket packet = new DatagramPacket( new byte [1024], 1024 );<br>
s.receive( packet );<br>
String message = new String( packet.getData() );<br>
System.out.println( message.trim() );<br>
}<br>
}<br>
}<p>
I do believe they are UDP Packets, I tried TCP/IP, I didn't get anything.. if anyone has any suggestions as to just "listening" on a port thats being used by another program, that'd be great.. Thanks!