public bool SendUserFiles(UserModel piUser) { try { IPAddress ipaddress = IPAddress.Parse("127.0.0.1"); client = new TcpClient(); client.Connect(new IPEndPoint(ipaddress, 9999)); byte[] buffer = StaticMethods.ObjectToByteArray(StaticValues.self.Files); NetworkStream clientStream = client.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); client.Close(); return true; } catch (Exception e) { return false; } }
public bool SendFile(FileModel piFile, UserModel piReciever) { try { IPAddress ipaddress = IPAddress.Parse(piReciever.IP); client = new TcpClient(new IPEndPoint(ipaddress, 9999)); FileStream Fs = new FileStream(piFile.Path, FileMode.Open, FileAccess.Read); byte[] buffer = StaticMethods.ObjectToByteArray(Fs); NetworkStream clientStream = client.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); client.Close(); return true; } catch (Exception e) { return false; } }
public bool SendMessage(UserModel piUser, string piMessage) { try { IPAddress ipaddress = IPAddress.Parse(piUser.IP); client = new TcpClient(new IPEndPoint(ipaddress, 9999)); MessageModel message = new MessageModel(piMessage, piUser, StaticValues.self); byte[] buffer = StaticMethods.ObjectToByteArray(message); NetworkStream clientStream = client.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); clientStream.Write(buffer, 0, buffer.Length); clientStream.Flush(); client.Close(); return true; } catch (Exception e) { return false; } }
private void listUsers_SelectedIndexChanged(object sender, EventArgs e) { string ip = ivApi.GetUserIp(listUsers.SelectedItem.ToString()); UserModel user = new UserModel(listUsers.SelectedItem.ToString(), ip); ivClient.SendUserFiles(user); }
public MessageModel(string piMessage, UserModel piReciever, UserModel piSender) { this.ivMessage = piMessage; this.ivReciever = piReciever; this.ivSender = piSender; }