Thread Subject: pnet TCP connection bug

Subject: pnet TCP connection bug

From: Fan Li

Date: 10 Oct, 2008 06:21:48

Message: 1 of 1

I am using the latest 2.0.6 version of TCP/UDP/IP toolbox (pnet) on
Matlab R2008a with Win XP Pro SP3. I am setting up a pair of tcp
sockets on localhost to send/receive short messages. The overarching
goal is to have a server-client style communication between two matlab
processes for data acquisition during visual experiments.

Here are example code (one for the server side and one for client):

server side:
sockcon = pnet('tcpsocket', 8889); % only create this socket once
quit = false;
while ~quit
    serv=pnet(sockcon,'tcplisten', 'noblock');
    if serv ~= -1
        % if someone connected to this data socket
        pnet(serv,'setreadtimeout', 1);
        received = pnet(serv,'readline','noblock');
        received
        pnet(serv, 'close');
    end
end

client side:
sockcon = pnet('tcpsocket', 8888); % only create this socket once
con=pnet('tcpconnect','localhost',8889);
pnet(con,'setwritetimeout', 1);
cmd = 'here is a test command';
pnet(con,'printf', '%s\n', cmd);
pnet(con, 'close');



To run, create both sockets (one in each matlab process), then let the
server-side loop while listening for a tcp connection. The client side
code sends a command to the server, which should be picked up by the
"readline".

The odd behavior that I am getting is that sometimes the server
successfully receives the message, but sometimes returns an empty
string from the readline command. It seems to be random, and I cannot
see a pattern in when it returns empty string versus the correct
string.

Can anyone duplicate this or has anyone seen this kind of behavior
before?

Thanks,
Fan

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com