Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
sister-kering
IF3230-Tugas-Besar-Sister-2015
Commits
1ab55b7a
Commit
1ab55b7a
authored
Apr 21, 2015
by
Rafi Ramadhan
Browse files
clientHandler
parents
ecf70eb1
74590d5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/server/GrandQuestServer/src/grandquestserver/ClientHandler.java
View file @
1ab55b7a
...
...
@@ -9,6 +9,7 @@ package grandquestserver;
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.sql.SQLException
;
...
...
@@ -24,7 +25,7 @@ public class ClientHandler extends Thread {
private
Socket
socketListener
;
public
ClientHandler
(
ServerSocket
sock
)
throws
IOException
{
System
.
out
.
println
(
"Waiting for client on
port
"
+
sock
.
getLocalPort
()
+
"..."
);
System
.
out
.
println
(
"Waiting for client on
"
+
InetAddress
.
getLocalHost
().
getHostAddress
()+
":
"
+
sock
.
getLocalPort
()
+
"..."
);
socketListener
=
sock
.
accept
();
System
.
out
.
println
(
"Just connected to "
+
socketListener
.
getRemoteSocketAddress
());
}
...
...
@@ -39,11 +40,12 @@ public class ClientHandler extends Thread {
response
=
in
.
readUTF
();
DataOutputStream
out
=
new
DataOutputStream
(
socketListener
.
getOutputStream
());
switch
(
parse
.
parseJSON
(
response
,
"method"
))
{
case
"login"
:
String
login
=
handler
.
Login
(
response
);
out
.
writeUTF
(
login
);
out
.
writeUTF
(
handler
.
Login
(
response
)
)
;
break
;
case
"signup"
:
out
.
writeUTF
(
handler
.
Signup
(
response
));
...
...
src/server/GrandQuestServer/src/grandquestserver/GrandQuestServer.java
View file @
1ab55b7a
...
...
@@ -9,6 +9,8 @@ package grandquestserver;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
*
...
...
@@ -26,9 +28,13 @@ public class GrandQuestServer {
*/
public
static
void
main
(
String
[]
args
)
throws
IOException
,
SQLException
,
ClassNotFoundException
,
InstantiationException
,
IllegalAccessException
{
int
port
=
8000
;
List
<
Thread
>
clientList
=
new
ArrayList
<>();
ServerSocket
serverSock
=
new
ServerSocket
(
port
);
Thread
t
=
new
ClientHandler
(
serverSock
);
t
.
start
();
while
(
true
)
{
Thread
t
=
new
ClientHandler
(
serverSock
);
t
.
start
();
clientList
.
add
(
t
);
}
//DBHandler database = new DBHandler();
//database.addInventory("ardi", 2);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment