C # dynamic socket byte array [List <byte> not working]
I am sending a request to the device as a byte array, and I want the anwser device to receive it.
...
Socket deviceSocket = new Socket(server);
List<byte> coming = new List<byte>();
...
deviceSocket.Receive(coming)
Here the program gives the error: Error 1 The
best overloaded method match for 'System.Net.Sockets.Socket.Receive (byte [])' has some invalid arguments Error 2
Argument '1': cannot be converted from 'System.Collections.Generic.List 'in' byte [] '
How can i solve this?
Thanks.
+3
5 answers
Socket.Receive() , , , , .
, 2048 , :
byte[] buffer = new byte[2048];
int bytesReceived = 0;
// ... somewhere later, getting data from client ...
bytesReceived = deviceSocket.Receive( buffer );
Debug.WriteLine( String.Format( "{0} bytes received", bytesReceived ) );
// now process the 'bytesReceived' bytes in the buffer
for( int i = 0; i < bytesReceived; i++ )
{
Debug.WriteLine( buffer[i] );
}
, , , - , debug, :)
, , , ( ), . , , .
+1
byte[] coming = new byte[8];
deviceSocket.Receive(coming);
for (int i = 0; i < 8; i++)
{
xtxtComing.Text += coming[i].ToString() + " ";
}
[xtxtComing !
.
List<byte> coming1 = new List<byte>();
deviceSocket.Receive(coming1.ToArray());
for (int i = 0; i < coming1.ToArray().Length; i++)
{
xtxtComing.Text += "a " + coming1[i].ToString() + " ";
}
, xtxtComing . , , , < > .
, :)
0