I have an ethernet device (PIC microcontroller) that is programmed to receive simple commands via ethernet. I have it working perfectly using the Winsock2005DLL.Winsock control. I'm trying without success to convert the code to use the System.Sockets.Socket class instead. Where am I missing ?
With the following 'Winsock' code, a connection is made and the device responds correctly to the hex commands:
Winsock2005DLL.Winsock ws = new Winsock2005DLL.Winsock();
ws.RemotePort = 8888;
ws.RemoteServer = "10.0.0.10";
ws.Connect();
string s = "";
char cmd = (char)'\x00C0';
char[] bData = new char[] { (char)'\x00FE', (char)'\x00C0', (char)'\x00FF' };
foreach (char c in bData)
s += c.ToString();
ws.Send(s);
This 'Socket' code however, creates the connection successfully, but the device DOESN'T respond to the hex data that is sent.
System.Net.EndPoint ep = new IPEndPoint(IPAddress.Parse("10.0.0.10"), 8888);
System.Net.Sockets.Socket sckt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sckt.Connect(ep);
string s = "";
char cmd = (char)'\x00C0';
char[] bData = new char[] { (char)'\x00FE', (char)'\x00C0', (char)'\x00FF' };
foreach (char c in bData)
s += c.ToString();
byte[] bitData = System.Text.Encoding.ASCII.GetBytes(bData);
sckt.Send(bitData);
Any help would be greatly appreciated.