G
Guest
I'm sending a message from VB.net (2003) to a C++ app via TCP sockets of
values 1 to 328. The message is a WORD value where I have to manage both
bytes for the WORD. I'm sending and receiving data from the C++ app with no
problem between the values of 1 to 127 and 256 to 328, but the application
receives garabage between 128 and 255. My current test syntax is as follows:
Dim nodeid As Integer = CType(txtMessage.Text, Integer)
Dim nodes(5) As Char
nodes(0) = Chr(7) '<- 1st WORD, Message Type = 7 in low bit
nodes(1) = Chr(0) '<- 1st WORD, high bit is off
nodes(2) = Chr(6) '<- 2nd WORD, Length of message = 6
nodes(3) = Chr(0) '<- 2nd WORD, high bit off
'Here is where I'm having the problem:
'1-127 in the low bit works great. (nodes(4) = 127, nodes(5) = 0 ) =
127
'256 to 328 works great. (nodes(4) = 0, nodes(5) = 1) = 256
'I'm not sure how to use 128 through 255 for this message
nodes(4) = ChrW(nodeid) '3rd WORD, if we exceed 255 need to push
high bit
nodes(5) = Chr(0) '1 if greater than 256
Send(nodes)
Private Sub Send(ByVal sendData() As Char)
Try
Dim writer As New StreamWriter(MyClient.GetStream)
writer.Write(sendData)
writer.Flush()
Catch ex As Exception
Throw ex
End Try
Any help would be greatly appreciated, thanks.
End Sub
values 1 to 328. The message is a WORD value where I have to manage both
bytes for the WORD. I'm sending and receiving data from the C++ app with no
problem between the values of 1 to 127 and 256 to 328, but the application
receives garabage between 128 and 255. My current test syntax is as follows:
Dim nodeid As Integer = CType(txtMessage.Text, Integer)
Dim nodes(5) As Char
nodes(0) = Chr(7) '<- 1st WORD, Message Type = 7 in low bit
nodes(1) = Chr(0) '<- 1st WORD, high bit is off
nodes(2) = Chr(6) '<- 2nd WORD, Length of message = 6
nodes(3) = Chr(0) '<- 2nd WORD, high bit off
'Here is where I'm having the problem:
'1-127 in the low bit works great. (nodes(4) = 127, nodes(5) = 0 ) =
127
'256 to 328 works great. (nodes(4) = 0, nodes(5) = 1) = 256
'I'm not sure how to use 128 through 255 for this message
nodes(4) = ChrW(nodeid) '3rd WORD, if we exceed 255 need to push
high bit
nodes(5) = Chr(0) '1 if greater than 256
Send(nodes)
Private Sub Send(ByVal sendData() As Char)
Try
Dim writer As New StreamWriter(MyClient.GetStream)
writer.Write(sendData)
writer.Flush()
Catch ex As Exception
Throw ex
End Try
Any help would be greatly appreciated, thanks.
End Sub