Main Board > Programming
Reading simple data from a TCP channel
martinp:
Hello everyone, just a simple question.
I have an incoming TCP data stream I want to capture. For example port 9004.
I've created a simple incoming server routine. Not sure if I needed KEEPALIVE but
let TCP=unt; open (TCP,bsz=4096,err=ERR_PORT)"[tcp];9004;KEEPALIVE"
READ_NEXT:
read record (TCP,err=ERR_READ)A$
print "Got: ",A$
goto READ_NEXT
Similarly I ran a linux "nc capture command" capturing data from another port which has the same data being sent to it.
What I am noticing is occasionally the PVX program does something like this:
Almost like a terminator character is received on the port and it registers part of the data then it continues on the next read fine. So I would have to concatenate the data.
The nc command however does not break apart any data.
I am just wondering if I need to change anything in this routine. Thanks.
Mike King:
You have specified a blocking factor of 4K so every time you read the most you will get back is 4K regardless of how much has been received.
Your PRINT command will then insert a visible line break on the output -- the line feed is not in the data but simply a result of the PRINT statement not having a trailing comma..
Try:
--- Code: --- let TCP=unt; open (TCP,bsz=4096,err=ERR_PORT)"[tcp];9004;KEEPALIVE"
READ_NEXT:
read record (TCP,err=ERR_READ)A$
print A$,
goto READ_NEXT
--- End code ---
martinp:
Thanks Mike but this data is coming in very slow like as you can see by the time stamp. Every few seconds very small data chunks?
martinp:
Let me resend with this picture I had this code with my time stamp
0040 let TCP=unt; open (TCP,bsz=4096,err=ERR_PORT)"[tcp];9004;KEEPALIVE"
0050 read record (TCP,err=ERR_READ)A$
0060 let TIME$=dte(0:%DATTIM_MSK$)
0070 print TIME$+" Got: ",A$
Mike King:
Yes but TCP is a streaming transmission so arrival times are never assured. A transmission error somewhere along the stream can cause a delay/small packet at any time.
Also, if you receiving small intermittent packets I would suggest you add the option NODELAY to disable the Nagles algorithm on the connection, it is normally enabled on TCP. (See Nagles Algorithm at https://en.wikipedia.org/wiki/Nagle%27s_algorithm). It also possible the sender may need to disable the algorithm to provide an even flow of data.
All that being said, did the example I posted with the trailing comma resolve what you seeing?
Navigation
[0] Message Index
[#] Next page
Go to full version