using System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using System.Text; namespace Socket_Server{ public class Program { public static void Main() { using (System.Net.Sockets.Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket.Bind(new IPEndPoint(IPAddress.Any, 10100)); socket.Listen(1); { while (true) using (Socket NetduinoSocket = socket.Accept()) { byte[] buffer = Encoding.UTF8.GetBytes("You Are Now Connected....."); NetduinoSocket.Send(buffer, 0, buffer.Length, 0); bool keepAlive = true; while (keepAlive) { if (NetduinoSocket.Poll(1, SelectMode.SelectRead)) { byte[] bytes = new byte[10]; int count = NetduinoSocket.Receive(bytes); char[] chars = Encoding.UTF8.GetChars(bytes); string position = new string(chars, 0, count); Debug.Print(position); } } } } } } }}
Edited by Chris Walker, 29 December 2012 - 03:03 AM.
added [code][/code] tags