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
Aryya Dwisatya W
IF3230-Tugas-Besar-Sister-2015
Commits
9f001f81
Commit
9f001f81
authored
Apr 28, 2015
by
adwisatya
Browse files
Cleaning up #2
parent
50757501
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/server/build/built-jar.properties
View file @
9f001f81
#Tue, 28 Apr 2015
19:46:55
+0700
#Tue, 28 Apr 2015
20:32:32
+0700
C\:\\Users\\adwisatya\\Documents\\Semester\
6\\Tugas\\IF3230\
Sister\\IF3230-Tugas-Besar-Sister-2015\\src\\
server
=
src/server/build/classes/thealchemist/Client.class
View file @
9f001f81
No preview for this file type
src/server/src/thealchemist/Client.java
View file @
9f001f81
...
...
@@ -42,6 +42,7 @@ import org.json.JSONException;
import
org.json.*
;
import
org.json.JSONObject
;
import
org.json.simple.parser.JSONParser
;
import
static
thealchemist
.
TCPServer
.
portNumber
;
/**
*
* @author adwisatya
...
...
@@ -118,6 +119,12 @@ public class Client extends Thread{
out
.
print
(
tmpStr
);
System
.
out
.
println
(
"Response: "
+
tmpStr
);
}
public
void
sendToOthers
(
String
host
,
int
port
,
String
strToSent
)
throws
IOException
{
Socket
senderSocket
=
new
Socket
(
host
,
port
);
PrintStream
outToOthers
=
new
PrintStream
(
senderSocket
.
getOutputStream
());
outToOthers
.
print
(
strToSent
);
}
public
void
checkCommand
(
String
cmd
)
throws
IOException
,
NoSuchAlgorithmException
,
JSONException
{
//cmdJoin();
System
.
out
.
println
(
"Request: "
+
cmd
);
...
...
@@ -202,15 +209,14 @@ public class Client extends Thread{
for
(
int
i
=
0
;
i
<
objArr
.
length
();
i
++){
objArr
.
getJSONObject
(
i
).
get
(
"ip"
);
objArr
.
getJSONObject
(
i
).
get
(
"port"
);
if
(
servers
.
contains
(
objArr
.
getJSONObject
(
i
))){
System
.
out
.
println
(
"Masukkan server baru
"
);
if
(
!
servers
.
contains
(
objArr
.
getJSONObject
(
i
))){
System
.
out
.
println
(
"Masukkan server baru
:"
+
objArr
.
getJSONObject
(
i
).
toString
()
);
servers
.
add
(
objArr
.
getJSONObject
(
i
).
toString
());
}
}
}
catch
(
JSONException
ex
)
{
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
}
System
.
out
.
println
(
request
);
}
public
void
cmdJoin
()
throws
IOException
,
JSONException
{
String
response
=
""
;
...
...
@@ -416,13 +422,26 @@ public class Client extends Thread{
}
/* Sukses */
public
void
cmdFindOffer
(
int
itemId
)
throws
IOException
,
NoSuchAlgorithmException
,
JSONException
{
JSONObject
obj
=
new
JSONObject
();
try
{
obj
=
database
.
getOfferList
(
itemId
);
}
catch
(
ClassNotFoundException
ex
)
{
Logger
.
getLogger
(
Client
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"method"
,
"findoffer"
);
obj
.
put
(
"item"
,
itemId
);
String
hostname
;
int
port
;
for
(
int
i
=
0
;
i
<
servers
.
size
();
i
++){
//System.out.println(servers.get(i).toString());
hostname
=
utility
.
JSONtoString
(
"ip"
,
servers
.
get
(
i
).
toString
());
port
=
new
Integer
(
utility
.
JSONtoString
(
"port"
,
servers
.
get
(
i
)));
sendToOthers
(
hostname
,
port
,
obj
.
toString
());
System
.
out
.
println
(
hostname
+
" "
+
port
+
" "
+
obj
.
toString
());
}
sendToClient
(
obj
.
toString
());
// try {
// obj = database.getOfferList(itemId);
// } catch (ClassNotFoundException ex) {
// Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
// }
}
/* Sukses */
public
String
cmdSendAccept
(
String
token
,
String
offer_token
)
throws
IOException
,
NoSuchAlgorithmException
,
JSONException
{
...
...
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