Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java sniffer - Socket listener  RSS feed

 
David Brossard
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to write a piece of code that'll sit on a computer and read incoming streams on any given port, without consuming it.

For instance, this piece of code would be a process sitting in front of a server, and seeing all the traffic going through.

I did write a piece of code as follows. It manages to read HTTP requests byte by byte. However it consumes the message.

Thanks for your help.

 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TCP/IP permits only one "listener" per host (i.e. combination of IP address and port#). In this case, that's your guy (your HttpListener). If anybody else tried to listen on that port on that host (regardless of whether or not they were doing it in Java, in C/C++, or in any other language), they'd get a "port in use" error.

The best you can do in Java is implement a "proxy": you listen and accept() connections on one host/port, then forward whatever you get to a different host/port.

Packet sniffers (like Ethereal or iptrace, for example) are implemented using "raw sockets". Java doesn't support raw sockets.

'Hope that helps .. PSM
[ January 09, 2006: Message edited by: Paul Santa Maria ]
 
David Brossard
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes what you say does help me. Thanks a bunch. It's much clearer.

I had noticed the port error message when trying to run my pgm while a server was also running on the same port...

Another small question. So far my piece of code reads byte by byte and hangs instead of displaying the full msg once it's arrived. Is there another way to read?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!