Commit 757b459a authored by mamat-rahmat's avatar mamat-rahmat
Browse files

findoffer udah implementasi tapi masih ngebug (kena parse exception) pas di client

parent fc52db4c
......@@ -410,6 +410,7 @@ def handler(a, c):
kriteria1Object = {"offered_item" : item}
offer_all = []
#ambil dari offer di server sendiri
for temp in database.offerCollection.find(kriteria1Object):
data = []
data.append( temp["offered_item"] )
......@@ -418,8 +419,37 @@ def handler(a, c):
data.append( temp["n_item2"] )
data.append( temp["availability"] )
data.append( temp["offer_token"] )
print("+++++" + str(data))
offer_all.append(data)
#ambil dari offer di server lain
for server in listActiveServer:
if (server["ip"] != hostLaptop):
print(server["ip"], server["port"])
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect((server["ip"],server["port"]))
message = '{ "method" : "findoffer", "item" : ' + str(item) + '}'
print(message)
s1.send(str.encode(message))
tm = s1.recv(4096)
tmString = tm.decode("utf-8")
print(tmString)
tmJSON = json.JSONDecoder().decode(tmString)
if (tmJSON["status"] == "ok"):
offers = tmJSON["offers"]
for offer in offers:
data = []
data.append( offer[0] )
data.append( offer[1] )
data.append( offer[2] )
data.append( offer[3] )
data.append( offer[4] )
data.append( offer[5] )
print("+++++" + str(data))
offer_all.append(data)
dictResponse = { "status" : "ok", "offers" : offer_all }
response = str(dictResponse)
......@@ -474,7 +504,7 @@ def handler(a, c):
token = dataJSON['token']
offer_token = dataJSON['offer_token']
kriteria1Object = {"offer_token": offer_token}
if (database.marketCollection.find(kriteria1Object).count() != 0):
if (database.offerCollection.find(kriteria1Object).count() != 0):
# Dapat jumlah item yang dioffer beserta nama itemnya
offer = database.marketCollection.find_one(kriteria1Object)
n_offer = offer['n_item1']
......
{
"name": "lima",
"width": 5,
"height": 5,
"map": [
[
7,
9,
4,
8,
6
4,
8,
8
],
[
7,
6,
2,
3,
9
4,
5,
9,
3
],
[
4,
8,
6,
0,
1,
4,
1
8,
5
],
[
7,
7,
0,
5,
8
6,
9,
7
],
[
0,
3,
0,
4,
8,
2
1,
9,
5
]
],
"height": 5,
"name": "satu"
]
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment