Jump to content

How do I capture data sent to a TCP port? e.g. Port 4001?


Transistor

Recommended Posts

I have a PC based vision inspection system capable of sending data strings of the measurements and results (possibly in XML format - I don't know yet). I can specify an IP address and port number on the sending application. I want to capture the measurement data and log it to a database.

 

Q1. What Linux app can I run to monitor the port - say port 4001? (This should show me the raw data so I understand what's being transmitted.)

 

Q2. What's the best way to capture data from that port using a php script? e.g. Can I redirect port 4001 to run a particular php script every time something shows up on that port?

 

Many thanks.

What's the best way to capture data from that port using a php script? e.g. Can I redirect port 4001 to run a particular php script every time something shows up on that port?

 

This ought answer both questions. You can build a sockets server to listen to that port, I'm not sure php is the best solution for such a thing, but its possible. Take a look at the sockets extension.

Thanks, Thorpe.

I've done some more reading and think that TCPDUMP might get me started. http://www.tcpdump.org/tcpdump_man.html. I'll try

tcpdump 'tcp port 4001

As far as I can make out it should display all traffic in (and out) on port 4001.

 

I've used php sockets on another small application but it was run from a CRON job. In this case I need to run a script every time traffic comes in on port 4001. I realise I can't leave a PHP script running waiting for an event. I'll see what I can come up with.

 

Anyone else?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.