コード例 #1
0
        public override void Send(string text)
        {
            Thread tSendToServer = new Thread(delegate() {
                try {
                    MyNetwork.Write(client, text);
                } catch {
                    ConnectionLost();
                }
            });

            tSendToServer.IsBackground = true;
            tSendToServer.Start();
            // Echo text will be sent back by the server
        }
コード例 #2
0
ファイル: ServerWindow.cs プロジェクト: sun123zxy/Chatroom
        public void SendToUser(User user, string text, CallBack callBack = null)
        {
            Thread tSendToUser = new Thread(delegate() {
                try {
                    MyNetwork.Write(user.socket, text);
                } catch {
                    Offline(user);
                }
                if (callBack != null)
                {
                    callBack();
                }
            });

            tSendToUser.IsBackground = true;
            tSendToUser.Start();
        }
コード例 #3
0
        void Connect(string ip, int port)
        {
            try {
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                client.Connect(ip, port);
                MyNetwork.Write(client, username); //Send username
            } catch {
                ConnectionLost();
                return;
            }
            EnableInput();

            Thread tRAA = new Thread(delegate() { ReadAndAct(); });

            tRAA.IsBackground = true;
            tRAA.Start();
        }