- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Re: Windows socket client drops the last byte of e...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 06:25 AM
тАО11-17-2010 06:25 AM
Windows socket client drops the last byte of every packet
I would like to include more information in my messages and I cannot find a way to make this work. If I knew 100% how long the packets will be on the network, I could work around this by including an extra byte in just the right places. However, I don't want to make any assumptions about the length of the packets.
Does anyone have any suggestions about what the best solution is to this problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 06:53 AM
тАО11-17-2010 06:53 AM
Re: Windows socket client drops the last byte of every packet
Can You show us the loop done on the receiver(select,recv,read)?
Basically there two ways for a protocol:
(1) the protocol is 'binary': each message starts with a byte (or word-)count, and the receiver reads until the counted bytes are read.
(2) the protocol is (ascii-)text based: then usually the receiver reads until a terminator sequence (usually
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 07:06 AM
тАО11-17-2010 07:06 AM
Re: Windows socket client drops the last byte of every packet
Private Sub ReceiveMsg()
Dim nTotalBytes As Integer
Dim nNumBytes As Integer
Dim nMsgType As Short
Dim nMsgLen As Short
Dim ind As Integer
Try
nNumBytes = -1
While (nNumBytes <> 0)
nTotalBytes = 0
RecvBuffer.Initialize()
nNumBytes = ClientSocket.Receive(RecvBuffer, nTotalBytes, 4, SocketFlags.None)
If nNumBytes > 3 Then
SyncLock ClientSocket
AppendText("")
AppendText("Message Received " & Str(nNumBytes) & " Bytes")
nTotalBytes = nTotalBytes + nNumBytes
nMsgType = BitConverter.ToInt16(RecvBuffer, 0)
nMsgLen = BitConverter.ToInt16(RecvBuffer, 2)
If nMsgLen > 8191 Then
AppendText(" Error - Message length invalid: " & Str(nMsgLen))
nMsgLen = 250
End If
While (nTotalBytes < nMsgLen And nNumBytes > 0)
nNumBytes = ClientSocket.Receive(RecvBuffer, nTotalBytes, (nMsgLen - nTotalBytes), _
SocketFlags.None)
AppendText("Message Received " & Str(nNumBytes) & " Bytes")
nTotalBytes = nTotalBytes + nNumBytes
End While
End SyncLock
AppendText("Total Bytes Received = " & Str(nTotalBytes))
AppendText("MsgLen from Message = " & Str(nMsgLen))
Select Case nMsgType
Case 1
AppendText(" Liftpos = " & System.Text.Encoding.ASCII.GetString(RecvBuffer, 4, 1))
For ind = 0 To NUM_LOCATIONS - 1
SlabNo(ind) = System.Text.Encoding.ASCII.GetString(RecvBuffer, 5 + (ind * 12), 12)
Next
RefreshScreen()
Case Else
AppendText(" Unrecognized message type: " & Str(nMsgType))
End Select
End If
End While
Catch ex As Exception
' Tell the main thread to invoke DisconnectedUI
Dim cb As New SimpleCallback(AddressOf DisconnectedUI)
Me.Invoke(cb)
Return
End Try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 07:06 AM
тАО11-17-2010 07:06 AM
Re: Windows socket client drops the last byte of every packet
Now UDP? UDP has packets; one message, one datagram. You either get the message, or you don't. If you don't, you resend.
If this isn't the usual case of processing a stream into packets (and a late-arriving byte), and your code is doing assembly and disassembly as the data arrives, then your code probably has a bug. The numbers of different ways this can go off the rails is large; C and BASIC differ in how they index stuff, and C is quite fond of off-by-one bugs, or any number of other bug-like creatures in the respective critter zoos of C and BASIC.
It's also possible the underlying code has a bug, though any bugs lurking in an IP stack transport tend to show up all over the place; all sorts of stuff breaks.
I'll also mention that the underlying problems here have long been solved, as have most of the related problems of recovery and restarts and related. Writing socket code was commonplace a quarter century ago (and many of us suffered through the "fun" of debugging that stuff), but there are now good libraries and transports that can deal with this dreck. Even on VMS. I'd suggest looking at zeroMQ (0MQ) as a starting point, though there are various other options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 07:15 AM
тАО11-17-2010 07:15 AM
Re: Windows socket client drops the last byte of every packet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 08:42 AM
тАО11-17-2010 08:42 AM
Re: Windows socket client drops the last byte of every packet
1) VMS socket server sends a QIOW with the message length (400) encoded in the message. However, the length specified on the QIOW is 402.
2) Windows vb.Net client receives 4 bytes from the stream to get the msg type and msg length. It sees that the msg length is 400
3) Windows vb.Net client calculates the size of the rest of the message (400 - 4 = 396) and then receives 396 bytes.
4) The data received is missing two bytes of the data that was sent, but is happy because it thinks it is only supposed to receive 400 bytes instead of 402. It then waits for more data.
By Using TCPTRACE on OpenVMS, I see the stream of bytes split into two packets. The missing bytes are the last byte included in each packet. All of the data can be viewed in TCPTRACE, but the vb.Net client does not receive it. FYI the code pasted above is slightly different than the code I am currently using to try to test longer messages, but it operates the same way. (Meaning that I send 248 bytes with an encoded msg length of 247. I only add one extra byte, because the client only drops one byte due to the entire message being sent in a single packet.)
My client receives multiple messages that are identical with the exact same results every time.
If someone wants to see the details, I can send the current client code and the TCPTRACE output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 11:45 PM
тАО11-17-2010 11:45 PM
Re: Windows socket client drops the last byte of every packet
And what if You simply agree with the servers message format, and interpret the QIO length as "inclusive count", i.e.
402 = 2 byte count field, followed by 400 data bytes ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 11:51 PM
тАО11-17-2010 11:51 PM
Re: Windows socket client drops the last byte of every packet
Isn't it as simple as
400-2=398, and then the complete message is read ?
In other words, the message length field does only count itself and the data, not the preceding type code word ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 05:43 AM
тАО11-18-2010 05:43 AM
Re: Windows socket client drops the last byte of every packet
My Header (msg type/ msg size) is 4 bytes. The encoded length is inclusive, but this does not matter as long as the client knows whether the encoded length includes the header or not. I suppose it would be a little simpler on the client if it did not count the header.
The main point is this:
- If The QIOW has a length of 248 bytes, the client only receives 247. The last byte is missing.
- If the QIOW has a length of 402 bytes, the client only receives 400. It does not get one byte somewhere in the middle of the message or the very last byte.
I can't fathom what could cause this, since I know the data was delivered.
Right now I am trying, as a work around, to send two short messages so that I can be fairly certain that the last byte of each message will be dropped and not make any guesses about how big the packets will be.
This client has been run on multiple Windows XP systems and all operate the same way.
Thanks for your comments.
Dave Williams
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 06:24 AM
тАО11-18-2010 06:24 AM
Re: Windows socket client drops the last byte of every packet
There is no one-to-one mapping of reads to writes in TCP.
This is a fundamental aspect of how TCP works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 06:36 AM
тАО11-18-2010 06:36 AM
Re: Windows socket client drops the last byte of every packet
This points to an error in the receiving application. Maybe overlapping buffers or something.
Oswald
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 07:30 AM
тАО11-18-2010 07:30 AM
Re: Windows socket client drops the last byte of every packet
If you want to operate with the envisioned reliable datagram transport via TCP, then you get to implement your own "packet" disassembly code, and you have to look at and slide a window based on how many bytes each read has received.
This is one of various considerations and problems that arise with socket programming that have been solved before; sockets are among the oldest and most primitive and problematic interfaces. Stuff like zeromq is definitely a friend here, and that use then frees you up to add more value for your customers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 10:21 AM
тАО11-18-2010 10:21 AM
Re: Windows socket client drops the last byte of every packet
Having said that, I have an application that is functioning well by splitting the sent message into two separate QIOWs. I realize that this should have no bearing on what I receive, but it does. I am able to control which bytes get dropped in this manner.
Seeing no other explanation at the moment, I will call this good enough for now. Thanks, again.