Пример #1
0
        /// <summary>
        /// Close the TCP Connection
        /// </summary>
        public void OnClose()
        {
            try
            {
                //Fill the info for the message to be send
                ViewerData msgToSend = new ViewerData();
                msgToSend.Message = null;
                msgToSend.OPCommand = Command.Logout;

                byte[] byteData = msgToSend.ToByte();

                //Send it to the server
                clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
                clientSocket.Close();

                clientSocket = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// OnConnect : connect to server. Send Connect Message
        /// </summary>
        /// <param name="ar"></param>
        private void OnConnect(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndConnect(ar);
                Console.WriteLine("Connected");
                //We are connected so we login into the server
                ViewerData msgToSend = new ViewerData();
                msgToSend.OPCommand = Command.Login;
                msgToSend.Message = null;

                byte[] b = msgToSend.ToByte();
                //Send the message to the server
                Console.WriteLine("Try Send Welcome packet");
                clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Send a (Data) pack to the TCP Viewer
        /// </summary>
        /// <param name="pack">byte[1020] pack</param>
        public void SendDataPack(byte[] pack)
        {
            try
            {
                byte[] nPack = new byte[1020];
                pack.CopyTo(nPack, 4);
                //Fill the info for the message to be send
                ViewerData msgToSend = new ViewerData();
                msgToSend.Message = nPack;
                msgToSend.OPCommand = Command.DataPacket;

                byte[] byteData = msgToSend.ToByte();

                //Send it to the server
                clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
            }
            catch (Exception)
            {
                Console.WriteLine("Unable to send message to the server. OMLServerTCP: ");
            }
        }