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
Jonathan Sudibya
IF3230-Tugas-Besar-Sister-2015
Commits
4572a1f7
Commit
4572a1f7
authored
Apr 20, 2015
by
Kevin
Browse files
perbaiki conflict private.xml
parents
9677b203
650deeda
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/client/TCPClient/nbproject/private/private.xml
View file @
4572a1f7
...
...
@@ -3,7 +3,11 @@
<editor-bookmarks
xmlns=
"http://www.netbeans.org/ns/editor-bookmarks/2"
lastBookmarkId=
"0"
/>
<open-files
xmlns=
"http://www.netbeans.org/ns/projectui-open-files/2"
>
<group>
<<<<<<
< HEAD
<file
>
file:/C:/Users/Kevin%20Zhong/Documents/NetBeansProjects/Coba/src/client/TCPClient/src/TCPClient.java
</file>
=======
<file>
file:/C:/Users/Jonathan/Documents/NetBeansProjects/GrandQuest/src/client/TCPClient/src/TCPClient.java
</file>
>>>>>>> origin/JSON-connect
</group>
</open-files>
</project-private>
src/server/TCPServer/nbproject/private/private.xml
View file @
4572a1f7
...
...
@@ -4,7 +4,6 @@
<open-files
xmlns=
"http://www.netbeans.org/ns/projectui-open-files/2"
>
<group>
<file>
file:/C:/Users/Kevin%20Zhong/Documents/NetBeansProjects/Coba/src/server/TCPServer/src/crudDB/crudDB.java
</file>
<file>
file:/C:/Users/Kevin%20Zhong/Documents/NetBeansProjects/Coba/src/server/TCPServer/src/TCPServer.java
</file>
</group>
</open-files>
</project-private>
src/server/TCPServer/src/Client.java
0 → 100644
View file @
4572a1f7
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.Socket
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
org.json.simple.JSONObject
;
import
org.json.simple.JSONArray
;
import
org.json.simple.parser.JSONParser
;
import
org.json.simple.parser.ParseException
;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Jonathan
*/
class
Client
implements
Runnable
{
private
int
ID
;
private
String
threadName
;
private
Socket
connectionSocket
;
private
Thread
t
;
private
boolean
active
;
private
String
clientSentence
;
private
String
capitalizedSentence
;
public
Client
(
int
_id
,
Socket
_client
)
{
ID
=
_id
;
connectionSocket
=
_client
;
threadName
=
"Client-Listener-"
+
ID
;
active
=
true
;
System
.
out
.
println
(
"Created thread "
+
threadName
);
}
@Override
public
void
run
()
{
JSONParser
parser
=
new
JSONParser
();
System
.
out
.
println
(
"Running thread "
+
threadName
);
while
(
active
)
{
DataOutputStream
outToClient
=
null
;
BufferedReader
inFromClient
=
null
;
try
{
inFromClient
=
new
BufferedReader
(
new
InputStreamReader
(
connectionSocket
.
getInputStream
()));
clientSentence
=
inFromClient
.
readLine
();
if
(
clientSentence
!=
null
){
outToClient
=
new
DataOutputStream
(
connectionSocket
.
getOutputStream
());
System
.
out
.
println
(
"Received: "
+
clientSentence
);
Object
obj
=
parser
.
parse
(
clientSentence
);
if
(
obj
!=
null
){
JSONObject
array
=
(
JSONObject
)
obj
;
}
capitalizedSentence
=
clientSentence
.
toUpperCase
()
+
'\n'
;
outToClient
.
writeBytes
(
capitalizedSentence
);
}
else
{
active
=
false
;
}
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
ParseException
ex
)
{
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
finally
{
try
{
inFromClient
.
close
();
outToClient
.
close
();
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
}
System
.
out
.
println
(
"Thread "
+
threadName
+
" exiting..."
);
}
public
void
start
(){
if
(
t
==
null
)
{
t
=
new
Thread
(
this
,
threadName
);
t
.
start
();
}
}
}
src/server/TCPServer/src/ConnectionHandler.java
0 → 100644
View file @
4572a1f7
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.util.Vector
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Jonathan
*/
public
class
ConnectionHandler
implements
Runnable
{
private
Thread
t
;
private
String
threadName
;
private
ServerSocket
welcomeSocket
;
private
Vector
<
Client
>
clients
;
private
boolean
active
;
private
int
globalID
;
public
ConnectionHandler
(){
threadName
=
"Connection-Handler"
;
active
=
true
;
globalID
=
0
;
try
{
welcomeSocket
=
new
ServerSocket
(
6789
);
clients
=
new
Vector
<>();
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
ConnectionHandler
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
System
.
out
.
println
(
"Created thread "
+
threadName
);
}
@Override
public
void
run
()
{
System
.
out
.
println
(
"Running thread "
+
threadName
);
while
(
active
){
try
{
clients
.
add
(
new
Client
(
globalID
,
welcomeSocket
.
accept
()));
clients
.
lastElement
().
start
();
globalID
++;
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
ConnectionHandler
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
}
System
.
out
.
println
(
"Thread "
+
threadName
+
" exiting..."
);
}
public
void
start
(){
if
(
t
==
null
){
t
=
new
Thread
(
this
,
threadName
);
t
.
start
();
}
}
public
void
setActive
(
boolean
_active
)
{
active
=
_active
;
}
}
src/server/TCPServer/src/TCPServer.java
View file @
4572a1f7
...
...
@@ -13,21 +13,11 @@ import java.net.*;
import
org.json.simple.JSONObject
;
import
org.json.simple.parser.JSONParser
;
class
TCPServer
{
public
static
void
main
(
String
argv
[])
throws
Exception
{
String
clientSentence
;
String
capitalizedSentence
;
ServerSocket
welcomeSocket
=
new
ServerSocket
(
6789
);
for
(;;)
{
Socket
connectionSocket
=
welcomeSocket
.
accept
();
BufferedReader
inFromClient
=
new
BufferedReader
(
new
InputStreamReader
(
connectionSocket
.
getInputStream
()));
DataOutputStream
outToClient
=
new
DataOutputStream
(
connectionSocket
.
getOutputStream
());
clientSentence
=
inFromClient
.
readLine
();
System
.
out
.
println
(
"Received: "
+
clientSentence
);
capitalizedSentence
=
clientSentence
.
toUpperCase
()
+
'\n'
;
outToClient
.
writeBytes
(
capitalizedSentence
);
}
}
class
TCPServer
{
public
static
void
main
(
String
argv
[])
throws
Exception
{
ConnectionHandler
CH
=
new
ConnectionHandler
();
CH
.
start
();
}
}
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