Hi,
I am trying to communicate with an external device and i am trying to send a byte array to the external device via sockets but i am always getting a response the message size is too small so i am not sure what i have done wrong. Between the data type there should be no alignment present and all numbers are represented in little endian format. The char array is not null terminated as mentioned in the protocol specifications.
I have to send data based on a struct that embeds 2 other struct. So here's my vb.net code for the struct used to convert to byte array and the sending part. Thanks in advance.
Public Structure MESSAGETYPE_OIP_Login
Dim Header() As COMMANDHEADER
Dim UserName() As PSTRING
Dim Password() As PSTRING
End Structure
Public Structure COMMANDHEADER
Dim MessageType As UInt32
Dim Length As UInt32
Dim Reserved1 As UInt32
Dim Reserved2 As UInt32
End Structure
Public Structure PSTRING
Dim Length As UInt32
Dim CharArray() As Char
End Structure
Dim client as System.Net.Sockets.TcpClient = New System.Net.Sockets.TcpClient("192.168.20.93", 9401)
Dim networkStream As Net.Sockets.NetworkStream = client.GetStream()
Dim Login As MESSAGETYPE_OIP_Login
Login.Header.MessageType = 4485122
Login.Header.Reserved1 = 0
Login.Header.Reserved2 = 0
Login.Header.Length = Marshal.SizeOf(Login.Header)
Login.UserName.CharArray = "admin".ToCharArray
Login.UserName.Length = Login.UserName.CharArray.Length
Login.Password.CharArray = "admin".ToCharArray
Login.Password.Length = Login.Password.CharArray.Length
Dim StrtoBy() As Byte
Dim ptr As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(Login))
ReDim StrtoBy(Marshal.SizeOf(Login) - 1)
Marshal.Copy(ptr, StrtoBy, 0, Marshal.SizeOf(Login))
Marshal.FreeCoTaskMem(ptr)
networkStream.Write(StrtoBy, 0, StrtoBy.Length)