Skip to content
Snippets Groups Projects
Commit 7838aab5 authored by am13g23's avatar am13g23
Browse files

Upload New File

parent d999d524
No related branches found
No related tags found
No related merge requests found
import java.net.InetAddress;
import java.net.Socket;
public class SocketDetails{ //class to store details of the listen sockets of active users
private InetAddress ip;
private int port;
public SocketDetails(Socket socket, int passPort){ //on construction set the IP and port number
ip = socket.getInetAddress();
port = passPort;
}
public InetAddress getIp() { //returns the ip address
return ip;
}
public int getPort() { //returns the port number
return port;
}
public Socket getSocket() throws Exception{ //opens a socket back to the user and returns that
return new Socket(ip, port);
}
@Override
public int hashCode() { //hash code function so two objects with the same port and host address have the same hash
return (ip.getHostAddress() + port).hashCode();
}
@Override
public boolean equals(Object obj) { //equals function that checks that the ips and ports match
return ((SocketDetails)obj).getIp().equals(ip) && ((SocketDetails)obj).getPort() == port;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment