Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
Java Port Listening Posted by Ryan Shelley on 7 Jun 1999 at 9:47 PM
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!


Thread Tree
Ryan Shelley Java Port Listening on 7 Jun 1999 at 9:47 PM
Ryan Shelley sorry, meant *SOCKETS*.. not ports.. *nt* on 7 Jun 1999 at 10:41 PM
Barni Re: Java Port Listening on 8 Jun 1999 at 11:54 PM
Barni Re: Java Port Listening on 8 Jun 1999 at 11:56 PM
Ryan Shelley Re: Java Port Listening on 9 Jun 1999 at 7:22 PM
Barni Re: Java Port Listening on 10 Jun 1999 at 2:05 AM
Ryan Shelley Re: Java Port Listening on 10 Jun 1999 at 12:48 PM
Barni Re: Java Port Listening on 10 Jun 1999 at 11:12 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.