예제 #1
0
 /// <summary>
 ///   连接服务器
 /// </summary>
 public override void ConnectServer()
 {
     try
     {
         if (socket == null)
         {
             socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         }
         if (remoteIep == null)
         {
             remoteIep = new IPEndPoint(IPAddress.Parse(IP), Port);
         }
         socket.Connect(remoteIep);
         byte[] byteMessage =
             Encoding.UTF8.GetBytes(XmlCommand.GetLoginXml("") + SendSuffix);
         //序列化,并把把字符串转成字节数组
         socket.SendTo(byteMessage, remoteIep);
         //ShowToolStripItemText(labelItem1, Color.Black, "网络连接成功");
         ThreadStart myThreaddelegate = ReceiveMessage;
         myThread = new Thread(myThreaddelegate);
         myThread.IsBackground = true;
         myThread.Start();
     }
     catch (SocketException sex)
     {
         if (socket != null)
         {
             socket.Close();
         }
         socket = null;
         //AppUtil.WriteTxtLog("无法连接到服务器", sex.Message);
         //ShowToolStripItemText(statusStrip1, Color.Red, "网络连接断开");
         OnSocketUnConnected();
     }
     catch (Exception ex)
     {
         if (socket != null)
         {
             socket.Close();
         }
         socket = null;
         //AppUtil.WriteTxtLog("未知错误", ex.Message);
         //ShowToolStripItemText(statusStrip1, Color.Red, "网络连接断开");
         OnSocketUnConnected();
     }
 }
예제 #2
0
        /// <summary>
        /// Sends the jump.
        /// </summary>
        private void SendJump()
        {
            string strgps = XmlCommand.GetJump("");

            SendMessage(SocketManager.FirstOut, strgps);
        }