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); } }
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); }
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); }
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); }