예제 #1
0
        public bool Registration(string username, string password)
        {
            MessageToServer message = new MessageToServer
            {
                Command  = CommandToServer.ASK_REGISTRATION,
                Username = username,
                Password = password
            };

            byte[] bytes = message.EncodeMessage();
            _sender.Send(bytes);
            bytes = new byte[3072];
            _sender.Receive(bytes);
            MessageFromServer received = MessageFromServer.DecodeMessage(bytes);

            if (received.Command == CommandFromServer.ACCEPTED)
            {
                UserInfo.Id       = received.Id;
                UserInfo.Name     = received.Name;
                UserInfo.Username = username;
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public List <Contact> SearchContacts(string search)
        {
            MessageToServer message = new MessageToServer
            {
                Command = CommandToServer.SEARCH_CONTACTS,
                Name    = search
            };

            byte[] bytes = message.EncodeMessage();
            _sender.Send(bytes);
            bytes = new byte[3072];
            _sender.Receive(bytes);
            MessageFromServer received = MessageFromServer.DecodeMessage(bytes);

            return(received.Users);
        }
예제 #3
0
        public List <Contact> Contacts(int id)
        {
            MessageToServer message = new MessageToServer
            {
                Command = CommandToServer.GET_CONTACTS,
                Id      = id
            };

            byte[] bytes = message.EncodeMessage();
            _sender.Send(bytes);
            bytes = new byte[3072];
            _sender.Receive(bytes);
            MessageFromServer received = MessageFromServer.DecodeMessage(bytes);

            return(received.Users);
        }
예제 #4
0
        internal List <Message> GetMessages(int id)
        {
            MessageToServer message = new MessageToServer
            {
                Command  = CommandToServer.GET_MESSAGES,
                Id       = UserInfo.Id,
                TargetId = id
            };

            byte[] bytes = message.EncodeMessage();
            _sender.Send(bytes);
            bytes = new byte[3072];
            _sender.Receive(bytes);
            MessageFromServer received = MessageFromServer.DecodeMessage(bytes);

            return(received.Messages);
        }