Ejemplo n.º 1
0
        //----------------------------------------------------------------------------------
        public bool Connect(Form1 form, string hostname, int port)
        {
            try
            {
                _form = form;

                _tcpClient = new TcpClient();
                _tcpClient.Connect(hostname, port);

                _stream = _tcpClient.GetStream();
                _writer = new BinaryWriter(_stream, Encoding.UTF8);
                _reader = new BinaryReader(_stream, Encoding.UTF8);

                _thread = new Thread(new ThreadStart(ProcessServerResponse));
                _thread.Start();

                NicknamePacket nickNamePacket = new NicknamePacket("Bill");
                Send(nickNamePacket);
            }
            catch (Exception e)
            {
                _form.Invoke(new RecieveMessageDelegate(_form.AppendText), new object[] { "Exception: " + e.Message });
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
 //----------------------------------------------------------------------------------
 public void SetNickname(string nickname)
 {
     name = nickname;
     NicknamePacket chatMessagePacket = new NicknamePacket(nickname);
     Send(chatMessagePacket);
 }