tcp/ip communcation in linux

11 views (last 30 days)
tlawren
tlawren on 11 May 2012
I'm trying to get data from a device via TCP/IP in Linux and I'm having trouble. My device looks for a machine with specified IP address and if it finds it, it transmits data to port 1300 on that machine once every second. I can successfully collect data from the device in Matlab on Windows, but I'm having problems getting the same code to work in Linux. I'm using pnet from FEX. Here are the two lines that seem to be the crux of my problem.
sockcon = pnet('tcpsocket',1300);
con = pnet(sockcon,'tcplisten');
In Windows, con is set to 1 to indicate that the connection is established. I can then read and process the data in another body of code. In Linux though, the second line never finishes. It hangs because it blocks and the timeout is set to Inf by default. Turning off blocking and setting a finite timeout don't help. con is always returned as -1 to indicate that an error occurred.
Does anyone have experience using pnet in Linux (64-bit)? Are there other tools I can use? I've tried
but I always get errors due to timeouts. Basically, I want to just open a tcp socket on port 1300 and read data off it when it is written. It would be nice to have bytesavailable like functionality, but that may be asking for too much.
  2 Comments
Walter Roberson
Walter Roberson on 11 May 2012
I believe you should be able to use the FEX contribution tcpudpip()
I do not know why you are getting the timeouts, though.
Your task would appear to be more suited to udp than tcp, but if the device is using tcp then you have to live with it.
Note: if it had been the instrument control toolbox you had been using, then setting it up as a server was not supported until somewhere in R2011*
tlawren
tlawren on 11 May 2012
I believe I am using tcpudpip(). It is what I am calling pnet.
http://www.mathworks.com/matlabcentral/fileexchange/345-tcpudpip-toolbox-2-0-6

Sign in to comment.

Answers (1)

Jason Ross
Jason Ross on 11 May 2012
Does your Linux machine have a firewall running, or something like SELinux enabled, that will also block ports? You could need to configure the port to be opened for communication.
Also, there's a possibility that something else is blocking you. If you run "netstat", you can get a list of what ports are in use and see if there is a collision going on (on either end).
  3 Comments
tlawren
tlawren on 11 May 2012
Also, I've checked to ensure that data is actually being sent to the port using tcpdump.
Jason Ross
Jason Ross on 11 May 2012
I'm not familiar with it at all, sorry. Make sure to check the other end (if possible) to see if the port is in use from something else.
Other than that, I've got few other suggestions that don't involve firing up the packet sniffer to see what's going on. Hopefully someone else has more elegant tools.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!