Did someone try to communicate with PC over sockets?
I try to build Windows form application and connect it to spider, but having some problems. If someone already do it i will be happy if that somebody share some code.
Socket don’t have any events (DataAvailable) and i am getting: "No connection could be made because the target machine actively refused it 192.168.1.55:1721"
Spider (server) code is:
public void InitServer()
{
if (Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces().Length < 1)
{
Debug.Print("No Active network interfaces. ");
}
else
{
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface NI = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0];
NI.EnableStaticIP(cIP, cSubnetMask, cGateway);
IPAddress hostIP = IPAddress.Parse(NI.IPAddress);
//WEB
_WebSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint epWeb = new IPEndPoint(hostIP, cHttpPort);
_WebSocket.Bind(epWeb);
_WebSocket.Listen(1);
//PC
_PCSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint epPC = new IPEndPoint(hostIP, cHttpPort);
_PCSocket.Bind(epPC);
_PCSocket.Listen(1);
Thread threadWeb = new Thread(ListenWeb);
threadWeb.Start();
Thread threadPC = new Thread(ListenPC);
threadPC.Start();
}
}
private void ListenWeb()
{
Debug.Print("listening...");
while (true)
{
try
{
Socket newSock = _PCSocket.Accept();
Debug.Print("Accepted a connection from " + newSock.RemoteEndPoint.ToString());
byte[] messageBytes = Encoding.UTF8.GetBytes("Test");
newSock.Send(messageBytes);
newSock.Close();
}
catch (Exception e)
{
Debug.Print(e.Message);
}
}
}
private void ListenPC()
{
Debug.Print("listening...");
while (true)
{
try
{
Socket newSock = _WebSocket.Accept();