Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SC4 - Messaging app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
am13g23
SC4 - Messaging app
Commits
7838aab5
Commit
7838aab5
authored
1 year ago
by
am13g23
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
d999d524
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SocketDetails.java
+34
-0
34 additions, 0 deletions
SocketDetails.java
with
34 additions
and
0 deletions
SocketDetails.java
0 → 100644
+
34
−
0
View file @
7838aab5
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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment