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
Stephen
IF3230-Tugas-Besar-Sister-2015
Commits
7c351592
Commit
7c351592
authored
Apr 21, 2015
by
melvinfonda
Browse files
Find offer kelar
parent
d38bec03
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/client/build/classes/tcpclient/TCPClient.class
View file @
7c351592
No preview for this file type
src/client/src/tcpclient/TCPClient.java
View file @
7c351592
...
...
@@ -188,6 +188,20 @@ public class TCPClient {
return
obj
;
}
public
JSONObject
findOfferJSON
(
String
token
,
int
id_item
)
{
JSONObject
obj
=
new
JSONObject
();
try
{
obj
.
put
(
"method"
,
"findoffer"
);
obj
.
put
(
"token"
,
token
);
obj
.
put
(
"item"
,
id_item
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
obj
;
}
public
JSONObject
cancelofferJSON
(
String
token
,
String
offer_token
)
{
JSONObject
obj
=
new
JSONObject
();
...
...
@@ -522,6 +536,30 @@ public class TCPClient {
return
responseJSON
;
}
public
JSONObject
findoffer
(
String
token
,
int
id_item
)
throws
Exception
{
openConnection
();
System
.
out
.
println
(
"Find Offer"
);
String
toSend
=
findOfferJSON
(
token
,
id_item
).
toString
();
//throw ioexception
DataOutputStream
outToServer
;
try
{
outToServer
=
new
DataOutputStream
(
clientSocket
.
getOutputStream
());
outToServer
.
writeBytes
(
toSend
+
'\n'
);
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
TCPClient
.
class
.
getName
()).
log
(
Level
.
SEVERE
,
null
,
ex
);
throw
new
Exception
(
"outtoserver find offer exception"
);
}
//ambil balasan server
BufferedReader
inFromServer
=
new
BufferedReader
(
new
InputStreamReader
(
clientSocket
.
getInputStream
()));
String
response
=
inFromServer
.
readLine
();
JSONObject
responseJSON
=
new
JSONObject
(
response
);
closeConnection
();
return
responseJSON
;
}
public
JSONObject
fetchitem
(
String
token
,
String
offer_token
)
throws
Exception
{
openConnection
();
...
...
@@ -691,7 +729,7 @@ public class TCPClient {
// response = client.offer(client.token, 0, 1, 7, 3);
// System.out.println(response.toString());
//
// response = client.
cancel
offer(client.token,
"a"
);
// response = client.
find
offer(client.token,
2
);
// System.out.println(response.toString());
//
// response = client.accept(client.token, "a");
...
...
src/server/build/classes/tcpserver/MySQLAccess.class
View file @
7c351592
No preview for this file type
src/server/build/classes/tcpserver/TCPServer.class
View file @
7c351592
No preview for this file type
src/server/src/tcpserver/MySQLAccess.java
View file @
7c351592
...
...
@@ -396,6 +396,39 @@ public class MySQLAccess {
return
response
;
}
public
JSONObject
findOffer
(
int
userID
,
int
id_item
)
throws
JSONException
{
open
();
JSONObject
response
=
new
JSONObject
();
try
{
preparedStatement
=
connect
.
prepareStatement
(
"SELECT * FROM offer WHERE "
+
"offered_item="
+
id_item
+
" AND available = 1;"
);
resultSet
=
preparedStatement
.
executeQuery
();
if
(
resultSet
.
first
())
{
response
.
put
(
"status"
,
"ok"
);
JSONArray
array
=
new
JSONArray
();
array
.
put
(
resultSet
.
getInt
(
"offered_item"
));
array
.
put
(
resultSet
.
getInt
(
"n1"
));
array
.
put
(
resultSet
.
getInt
(
"demanded_item"
));
array
.
put
(
resultSet
.
getInt
(
"n2"
));
array
.
put
(
resultSet
.
getBoolean
(
"available"
));
array
.
put
(
resultSet
.
getString
(
"offer_token"
));
response
.
put
(
"offers"
,
array
);
}
else
{
response
.
put
(
"status"
,
"error"
);
}
}
catch
(
SQLException
e
)
{
response
.
put
(
"status"
,
"error"
);
e
.
printStackTrace
();
}
close
();
return
response
;
}
public
JSONObject
fetchitem
(
int
userID
,
String
offer_token
)
throws
JSONException
{
open
();
...
...
src/server/src/tcpserver/TCPServer.java
View file @
7c351592
...
...
@@ -189,6 +189,16 @@ public class TCPServer implements Runnable {
}
}
public
JSONObject
findoffer
(
JSONObject
clientObject
)
throws
JSONException
{
if
(
clientObject
.
getString
(
"token"
).
equalsIgnoreCase
(
token
))
{
return
sql
.
findOffer
(
userID
,
clientObject
.
getInt
(
"item"
));
}
else
{
JSONObject
responseJSON
=
new
JSONObject
();
responseJSON
.
put
(
"status"
,
"error"
);
return
responseJSON
;
}
}
public
JSONObject
fetchitem
(
JSONObject
clientObject
)
throws
JSONException
{
if
(
clientObject
.
getString
(
"token"
).
equalsIgnoreCase
(
token
))
{
return
sql
.
fetchitem
(
userID
,
clientObject
.
getString
(
"offer_token"
));
...
...
@@ -356,6 +366,11 @@ public class TCPServer implements Runnable {
System
.
out
.
println
(
responseJSON
.
toString
());
outToClient
.
writeBytes
(
responseJSON
.
toString
()
+
"\n"
);
}
else
if
(
method
.
equalsIgnoreCase
(
"findoffer"
))
{
JSONObject
responseJSON
=
server
.
findoffer
(
clientObject
);
System
.
out
.
println
(
responseJSON
.
toString
());
outToClient
.
writeBytes
(
responseJSON
.
toString
()
+
"\n"
);
}
}
}
}
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