ServerConnection.cs 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. namespace Team.Communicate.Data
  2. {
  3. public class TcpConnection
  4. {
  5. public string Ip { get; }
  6. public bool Connected { get; internal set; }
  7. public int Port { get; }
  8. public TcpConnection(string ip,int port)
  9. {
  10. Ip = ip;
  11. Port = port;
  12. }
  13. public override bool Equals(object obj)
  14. {
  15. if (obj is TcpConnection serverConnection)
  16. {
  17. return Equals(serverConnection);
  18. }
  19. return false;
  20. }
  21. protected bool Equals(TcpConnection other)
  22. {
  23. return Ip == other.Ip && Port == other.Port;
  24. }
  25. public override int GetHashCode()
  26. {
  27. unchecked
  28. {
  29. var hashCode = Ip != null ? Ip.GetHashCode() : 0;
  30. hashCode = (hashCode * 397) ^ Port;
  31. return hashCode;
  32. }
  33. }
  34. }
  35. }