Ejemplo n.º 1
0
 /// <summary>
 /// 初始化socket服务器
 /// </summary>
 /// <param name="MySocketClass1"></param>
 public void initSocketServer(MySocketClass MySocketClass1)
 {
     try
     {
         MySocketClass1.ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         MySocketClass1.ServerSocket.Bind(new IPEndPoint(IPAddress.Parse(MySocketClass1.ip), MySocketClass1.port));
         MySocketClass1.ServerSocket.Listen(MySocketClass1.listenNum);
         MySocketClass1.exceptionString = null;
         AsyncCallback AsyncCallback1 = new AsyncCallback(AcceptCallback);
         MySocketClass1.ServerSocket.BeginAccept(AsyncCallback1, null);
     }
     catch (Exception e)
     {
         MySocketClass1.exceptionString = e.Message;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 初始化socket客户端
 /// </summary>
 /// <param name="MySocketClass1"></param>
 public void initSocketClient(MySocketClass MySocketClass1)
 {
     try
     {
         MySocketClass1.ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         MySocketClass1.ClientSocket.Connect(IPAddress.Parse(MySocketClass1.ip), MySocketClass1.port);
         MySocketClass1.exceptionString = null;
     }
     catch (Exception e)
     {
         MySocketClass1.exceptionString = e.Message;
     }
 }