AnsweredAssumed Answered

C Sockets/TCP Question on E5071B

Question asked by RobertLefevre on Jul 16, 2007
Latest reply on Nov 7, 2007 by odanzy
I am having this problem with recieving data over a Sockets/TCP connection in C#. Keep in mind that I am an intern

Currently, I send the ":SENS1:FREQ:Data?" command through the function at the end of this message and recieve 1601 data points (I recieve an ascii string and parse it into what I will use later on). Each data point has a corresponding 20 bytes associated with it, for a total of 32020 bytes in total, encoded to a string.

When I send it the ":CALC1:DATA:FDAT?" command to recieve the physical data, I encounter a problem. The analyzer is set-up is to send a logarithmic magnitude of the first trace, so I should expect two values to be recieved (the magnitude, a comma, a zero, then another comma) for a total of 64040 bytes recieved. When I send the command, though, it only will read 52224 bytes, and cut off the rest. I set the tcpClient buffer size high enough to read the whole string, but it still will not. When I view the TCPclient object while debugging, the TCPClient.Available = 11816, which would be 64040-52224. Does anyone have any clue what is going on? Is 52224 some kind of pre-determined buffer size?

I attached the code I am using.

public String SocketSendAndReadArray(String text)
    {
        tcpClient.ReceiveBufferSize = 65000;

        NetworkStream networkStream = tcpClient.GetStream();
        if (networkStream.CanWrite && networkStream.CanRead)
        {
            // the firmware server requires a \n at the end
            // of the message
            if (!text.EndsWith("\n")) text += "\n";

            // Does a simple write.
            Byte[] sendBytes = Encoding.ASCII.GetBytes(text);
            networkStream.Write(sendBytes, 0, sendBytes.Length);
            String returndata = "";
            int numBytes;
            byte[] bytes = new byte[tcpClient.ReceiveBufferSize];

            // Reads the NetworkStream into a byte buffer.
            do
            {
                numBytes = networkStream.Read(bytes, 0, (int)  
                                tcpClient.ReceiveBufferSize);
                 returndata += Encoding.ASCII.GetString(bytes, 0,
                                numBytes - 1);

            }
            while (numBytes == tcpClient.ReceiveBufferSize);
       
            return returndata;
        }
        else
            return "";
    }  

Outcomes