Question TCP/IP Communication Problem

mtbpatriot153

New member
Joined
Jun 15, 2009
Messages
1
Programming Experience
5-10
Hello there,

I've recently been having some trouble talking to a device I have connected remotely. Without getting into too much detail, the device has an IP address and firmware on it that automatically sends out a response when it receives a specific command.

The problem I'm having is I need to send the command three times in order to get back a response. The first time I get "??" (characters that can't display), and the second time I get nothing. When I send the command a third time, it returns exactly what I was expecting.

I don't believe the problem is with the device because HyperTerminal can connect to it (via TCP/IP) and send a command (once) and have it return appropriate data.

Here's my connect/receive code:
VB.NET:
Dim serverStream As NetworkStream = clientSocket.GetStream()
        Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("cd 3" & vbCrLf)
        serverStream.Write(outStream, 0, outStream.Length)
        outStream = System.Text.Encoding.ASCII.GetBytes("setswitch 1 1 1 1" & vbCrLf)
        serverStream.Write(outStream, 0, outStream.Length)
        serverStream.Flush()

        Dim returndata As String = System.Text.Encoding.ASCII.GetString(inStream)
        serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize))
        msg("Data from Server : " + returndata)

Any help you guys could give would be greatly appreciated!

Thank you,
Mike
 
I do custom AV work and we deal with this kind of thing all the time without know what the device is or how its actually whats to talk ... the first of my two suggestions would be to try a different type of encoding UTF7 or UTF8 maybe and I would almost say that the vbCrLf might need to change also ... why it works after the third time is anyones guess but I would love to hear what makes it actually work
 
Back
Top