文档详情

dotnet通讯.pdf

发布:2017-07-03约6.8万字共31页下载文档
文本预览下载声明
Socket 通讯: public class XmlSocket { //异步 socket 诊听 // Incoming data from client.从客户端传来的数据 public static string data = null ; // Thread signal.线程 用一个指示是否将初始状态设置为终止的布尔值初始化 ManualResetEvent 类的新实 例。 public static ManualResetEvent allDone = new ManualResetEvent(false); //static void Main(string[] args) //{ // StartListening(); //} public static void StartListening() { // Data buffer for incoming data. 传入数据缓冲 byte [] bytes = new Byte[1024]; // Establish the local endpoint for the socket. 建立本地端口 // The DNS name of the computer // running the listener is . IPAddress ipAddress; String ipString = ConfigurationManager.AppSettings.Get(SocketIP); if (ipString==null || ipString ==String.Empty) { IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); ipAddress = ipHostInfo.AddressList[0]; } else { ipAddress = IPAddress.Parse(ipString); } int port; String portString = ConfigurationManager.AppSettings.Get(SocketPort); if (portString==null || portString==String.Empty) { port = 11001; } else { port = int.Parse(portString); } IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port); // Create a TCP/IP socket. Socket listener = new Socket(AddressFamily.InterNetwork,
显示全部
相似文档