FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MultiClient-Java-Server/src/Client/Client.java at master · Am4nn/MultiClient-Java-Server · GitHub
Am4nn
/
MultiClient-Java-Server
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MultiClient-Java-Server
/
src
/
Client
/
Client.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (60 loc) · 2.16 KB
Breadcrumbs
MultiClient-Java-Server
/
src
/
Client
/
Client.java
Copy path
File metadata and controls
74 lines (60 loc) · 2.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package
Client
;
import
CLI
.
CLI
;
import
GUI
.
GUI
;
import
java
.
io
.
DataInputStream
;
import
java
.
io
.
DataOutputStream
;
import
java
.
io
.
IOException
;
import
java
.
net
.
Socket
;
import
java
.
util
.
logging
.
Level
;
import
java
.
util
.
logging
.
Logger
;
public
class
Client
{
public
static
Socket
socket
=
null
;
String
ipAddress
;
String
portNumber
;
public
static
DataInputStream
inputStream
;
public
static
DataOutputStream
outputStream
;
public
static
GUI
ui
;
public
static
String
name
;
public
Client
() {
ui
=
new
GUI
(
"Client"
);
this
.
init
();
this
.
startCommunication
();
}
private
void
init
() {
ipAddress
=
ui
.
read
(
"Input IP Address of Server"
,
"localhost"
);
portNumber
=
ui
.
read
(
"Input Port Number of Server"
,
"3000"
);
name
=
ui
.
read
(
"Enter your name :"
);
try
{
socket
=
new
Socket
(
ipAddress
,
Integer
.
parseInt
(
portNumber
));
inputStream
=
new
DataInputStream
(
socket
.
getInputStream
());
outputStream
=
new
DataOutputStream
(
socket
.
getOutputStream
());
// send client name and some other imp details if required
outputStream
.
writeUTF
(
name
);
ui
.
write
(
"Client Connected with Server on "
+
ipAddress
+
":"
+
portNumber
);
}
catch
(
IOException
e
) {
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
ui
.
write
(
e
.
getMessage
());
}
}
private
void
startCommunication
() {
Thread
readFromServer
=
new
Thread
(
new
ReadFromServer
());
Thread
writeToServer
=
new
Thread
(
new
WriteToServer
());
readFromServer
.
start
();
writeToServer
.
start
();
try
{
// wait for threads to die
readFromServer
.
join
();
writeToServer
.
join
();
}
catch
(
InterruptedException
e
) {
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
// after all threads dies - cleanup
try
{
outputStream
.
close
();
inputStream
.
close
();
socket
.
close
();
}
catch
(
IOException
e
) {
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
e
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL