c# - NetworkStream.Read did not get all the bytes after a null byte/s -
I am creating an application that can remotely control a device such as camera (Scopia XT5000 - Radvision) Will happen. I need to send an initialization command to the device so that I can send AT commands which will control the device.
Once I send the initial order, the server should answer it: ? ? \ 0 \ 0 \ 0 AT [& lt; IP400C9XT5000-03.01.00.0028 \ r ?? \ 0 \ 0 \ 0 ok \ r \ / Bytes 170 170 0 32 65 84 91 60 73 80 52 48 48 67 57 88 84 53 48 48 48 45 48 51 46 48 49 46 48 48 46 48 48 50 56 13 170 170 0 0 3 79 75 13 I have to debug Tried and received those values when I broke here serverStream.Read (instream, 0, inStream.Length); But every time I run programs without debugging or braking, it will give me different strings and bytes. Just like in the string ? \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 Bytes 170 170 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 What could be the problem? Is it: Full Code: read This works when you debug because, due to the extra time spent, the result of the network stream is fully received, so when references: is read, all data is available And is put into buffer
In the string
- Tap bytes?
- Carriage return? "\ R"?
- Multiple lines?
{TCP Client Client Socket = New System. met. Sockets. QP Client (); Public Form 1 () {Initialization (); } Private Zero form1_load (object sender, eventAgps E) {msg ("client initiate"); } Public Zero OpenSocket () {if (clientSocket.Connected) {clientSocket.Close (); } ClientSocket = New System.Net.Sockets.TcpClient (); ClientSocket.Connect ("10.0.3.202", 55003); Label1.Text = "Client Socket Program - Server Connected ..."; } Private Zero btnSend_Click (Object Sender, EventArgs e) {openSocket (); // Header bytes and initat bytes are the initialized commands to send commands to me ("int:"); NetworkStream Server Stream = Client Socket Gatestream (); // command byte to enable header bytes [] header = {170,170,0,0,0,8}; ServerStream.Write (header, 0, header.Length); ServerStream.Flush (); // Start the interface byte [] initat = System.Text.Encoding.ASCII.GetBytes ("AT [and IPv \ r"]; ServerStream.Write (initat, 0, initat.Length); ServerStream.Flush (); Byte [] instream = new byte [10025]; Server Stream. Read (Instream, 0, Instream. Lang); String returndata = System.Text.Encoding.ASCII.GetString (instream); Msg ("data to server:" + ratcattata); } Private Zero btnRight_Click (Object Sender, EventArgs e) {msg ("rights:"); NetworkStream Server Stream = Client Socket Gatestream (); To move the main camera in the right byte // AT command [] outstream3 = system.Text.Encoding.ASCII.GetBytes ("AT [& SY011R \ r"]; Server Stream. (Outstream 3, 0, Outstream 3. Lang); Byte [] InStream 2 = New Byte [48]; Server Stream Read (Instream 2, 0, InStream 2. Lang) string returndata = System.Text.Encoding.ASCII.GetString (inStream2); Message (Returndata);} Public Zero Message (String Mess) {textBox1.Text = textBox1.Text >> Environment.NewLine + "> + mesg;}}
read Returns the number of bytes, you have a 10025-byte buffer, but it is not complete after
read . You want to be able to read all the bytes as long as you want.
< / P>
Comments
Post a Comment