Commit 692f5fc1 authored by opelhoward's avatar opelhoward
Browse files

fix send find

parents 79c58fea b1c9f450
......@@ -27,8 +27,8 @@
<file leaf-file-name="sconnectionhandler.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-3.0181818" vertical-offset="7180" max-vertical-offset="7565">
<caret line="354" column="14" selection-start-line="354" selection-start-column="14" selection-end-line="354" selection-end-column="29" />
<state vertical-scroll-proportion="0.6909091" vertical-offset="5293" max-vertical-offset="7922">
<caret line="327" column="29" selection-start-line="327" selection-start-column="29" selection-end-line="327" selection-end-column="29" />
<folding>
<element signature="e#21#32#0" expanded="true" />
</folding>
......@@ -39,8 +39,8 @@
<file leaf-file-name="sclient.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/sclient.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="1275" max-vertical-offset="1819">
<caret line="70" column="0" selection-start-line="70" selection-start-column="0" selection-end-line="70" selection-end-column="0" />
<state vertical-scroll-proportion="0.0" vertical-offset="120" max-vertical-offset="2125">
<caret line="20" column="0" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
<folding>
<element signature="e#0#23#0" expanded="true" />
</folding>
......@@ -114,6 +114,7 @@
<sortByType />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<PATH>
......@@ -134,7 +135,6 @@
</PATH>
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
......@@ -310,8 +310,8 @@
</list>
<recent_temporary>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="Python.sclient" />
<item index="1" class="java.lang.String" itemvalue="Python.main" />
<item index="0" class="java.lang.String" itemvalue="Python.main" />
<item index="1" class="java.lang.String" itemvalue="Python.sclient" />
</list>
</recent_temporary>
</component>
......@@ -330,7 +330,7 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
<editor active="true" />
<editor active="false" />
<layout>
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24304539" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
......@@ -339,7 +339,7 @@
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32913387" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32913387" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
......@@ -374,6 +374,44 @@
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="7582">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#21#32#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/sclient.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="720" max-vertical-offset="1819">
<caret line="56" column="17" selection-start-line="56" selection-start-column="17" selection-end-line="56" selection-end-column="17" />
<folding>
<element signature="e#0#23#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/tradebox.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="51" max-vertical-offset="1207">
<caret line="36" column="70" selection-start-line="35" selection-start-column="54" selection-end-line="36" selection-end-column="70" />
<folding>
<element signature="e#22#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/user.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="174" max-vertical-offset="1190">
<caret line="20" column="55" selection-start-line="20" selection-start-column="46" selection-end-line="20" selection-end-column="55" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="6137">
......@@ -453,7 +491,6 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="306" max-vertical-offset="408">
<caret line="18" column="0" selection-start-line="18" selection-start-column="0" selection-end-line="18" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
......@@ -475,7 +512,6 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.6407035" vertical-offset="306" max-vertical-offset="816">
<caret line="33" column="55" selection-start-line="33" selection-start-column="55" selection-end-line="33" selection-end-column="55" />
<folding />
</state>
</provider>
</entry>
......@@ -490,7 +526,6 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="398">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
......@@ -498,7 +533,6 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.40201005" vertical-offset="10" max-vertical-offset="408">
<caret line="10" column="0" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
......@@ -514,7 +548,6 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="1.022613" vertical-offset="409" max-vertical-offset="1921">
<caret line="52" column="42" selection-start-line="52" selection-start-column="35" selection-end-line="52" selection-end-column="42" />
<folding />
</state>
</provider>
</entry>
......@@ -532,7 +565,6 @@
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.24623115" vertical-offset="5648" max-vertical-offset="6222">
<caret line="340" column="0" selection-start-line="340" selection-start-column="0" selection-end-line="340" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
......@@ -546,8 +578,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/sclient.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0" vertical-offset="1275" max-vertical-offset="1819">
<caret line="70" column="0" selection-start-line="70" selection-start-column="0" selection-end-line="70" selection-end-column="0" />
<state vertical-scroll-proportion="0.0" vertical-offset="120" max-vertical-offset="2125">
<caret line="20" column="0" selection-start-line="20" selection-start-column="0" selection-end-line="20" selection-end-column="0" />
<folding>
<element signature="e#0#23#0" expanded="true" />
</folding>
......@@ -556,8 +588,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/sconnectionhandler.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-3.0181818" vertical-offset="7180" max-vertical-offset="7565">
<caret line="354" column="14" selection-start-line="354" selection-start-column="14" selection-end-line="354" selection-end-column="29" />
<state vertical-scroll-proportion="0.6909091" vertical-offset="5293" max-vertical-offset="7922">
<caret line="327" column="29" selection-start-line="327" selection-start-column="29" selection-end-line="327" selection-end-column="29" />
<folding>
<element signature="e#21#32#0" expanded="true" />
</folding>
......
......@@ -32,6 +32,13 @@ print(response)
# move_list = []
# for x in range(0, response.get('width')):
# for y in range(0, response.get('height')):
# print('')
# print('invoking map')
# response = invoke(json.dumps({"method":"map","token":token}))
# move_list = []
# for x in range(0,response.get('width')):
# for y in range(0,response.get('height')):
# move_list.append((x,y))
# PASSED
......@@ -44,12 +51,17 @@ print(response)
# print(response)
# PASSED
print('')
print('invoking field')
response = invoke(json.dumps({"method": "field", "token":token}))
print(response)
response = invoke(json.dumps({"method": "field", "token":token}))
print(response)
# print('')
# print('invoking field')
# response = invoke(json.dumps({"method": "field","token":token}))
# print(response)
# response = invoke(json.dumps({"method": "field","token":token}))
# print(response)
# print('')
# print('invoking sendfind')
# response = invoke(json.dumps({"method": "sendfind","item": 2,"token":token}))
# print(response)
# PASSED
# print('')
......@@ -64,10 +76,10 @@ print(response)
# print(response)
# PASSED
# print('')
# print('invoking sendfind')
# response = invoke(json.dumps({"method": "sendfind","item": 2,"token":token}))
# print(response)
print('')
print('invoking sendfind')
response = invoke(json.dumps({"method": "sendfind","item": 2,"token":token}))
print(response)
# PASSED
# print('')
......@@ -75,6 +87,11 @@ print(response)
# response = invoke(json.dumps({"method": "inventory", "token":token}))
# print(response)
# print('')
# print('invoking offer')
# response = invoke(json.dumps({"method": "offer","token": token,"offered_item": 2,"n1": 1,"demanded_item": 2,"n2": 1}))
# print(response)
# PASSED
# print('')
# print('invoking tradebox')
......@@ -99,4 +116,4 @@ print(response)
# host = Socket.gethostname()
# port = 8000
# s.connect((host, port))
# time.sleep(10)
\ No newline at end of file
# time.sleep(10)
......@@ -8,7 +8,7 @@ from user import User
from map import Map
from tradebox import Tradebox
from market import Market
from threading import Thread
from ssocketio import SocketIO
class ConnectionHandler:
......@@ -241,50 +241,22 @@ class ConnectionHandler:
#tambahin server abusive
Market.clear(item)
offer_list = []
thread_list = []
# untuk setiap server lain
for other_server in self._server._server_list:
#bikin koneksi server
socket = Socket.socket()
socket.settimeout(SocketIO.SERVER_CONNECTION_TIMEOUT)
host = other_server.get('ip')
port = other_server.get('port')
# kalo ternyata tracker jangan direquest
if ((host == self._server.__class__.TRACKER_IP) and (port == self._server.__class__.TRACKER_PORT)):
continue
print('connecting to ',host,':',port)
socket.settimeout(SocketIO.SERVER_CONNECTION_TIMEOUT)
try:
socket.connect((host,port))
except Exception as e:
print('Error connecting to',host,':',port)
print(e)
continue
socketio = SocketIO(socket)
socketio.write_to_socket((json.dumps({'method':'findoffer','item':item})).encode('ascii'))
print('read offering from ',host,':',port)
#catch connection timeout
try:
data = socketio.read_from_socket()
except Exception as e:
print(e)
continue
if (data != None):
try:
response = json.loads(data.decode('utf-8'))
server_offer_list = response.get('offers',[])
print('Result : ',end='')
Market.add(item, server_offer_list, host, port)
print(server_offer_list)
offer_list.extend(server_offer_list)
except ValueError as ve:
i = 1 # do nothing
port = int(other_server.get('port'))
if (not ((host == self._server.__class__.TRACKER_IP) and (port == self._server.__class__.TRACKER_PORT))):
thr = FindOfferThread(host,port,item)
thread_list.append(thr)
thr.start()
for thr in thread_list:
thr.join()
for thr in thread_list:
# print(thr.get_result())
offer_list.extend(thr.get_result())
print(offer_list)
offer_list = Market.get_offers(item)
......@@ -438,4 +410,51 @@ class ConnectionHandler:
# # tulis data ke socket
# # be sure to handle socket exception
# def write_to_socket(self,data):
# recv = self._conn.send(data + b'\n')
\ No newline at end of file
# recv = self._conn.send(data + b'\n')
class FindOfferThread(Thread):
def __init__(self,target_ip,target_port, item):
Thread.__init__(self)
self._host = target_ip
self._port = target_port
self._item = item
self._result = []
def run(self):
socket = Socket.socket()
socket.settimeout(SocketIO.SERVER_CONNECTION_TIMEOUT)
self._result = []
print('Connect to ',self._host,':',self._port)
try:
socket.connect((self._host,self._port))
except Exception as e:
print('Error connecting to',self._host,':',self._port)
print(e)
return
socketio = SocketIO(socket)
socketio.write_to_socket((json.dumps({'method':'findoffer','item':self._item})).encode('ascii'))
print('read offering from ',self._host,':',self._port)
#catch connection timeout
try:
data = socketio.read_from_socket()
except Exception as e:
print(e)
return
if (data != None):
try:
response = json.loads(data.decode('utf-8'))
server_offer_list = response.get('offers',[])
Market.add(self._item, server_offer_list, self._host, self._port)
self._result = server_offer_list
print(self._result)
except ValueError as ve:
return
def get_result(self):
return self._result
......@@ -77,13 +77,13 @@ class Server:
print('Tracker error')
print(e)
return
print('tracker connected')
tracker_io = SocketIO(socket)
tracker_io.write_to_socket((json.dumps({'method':'join','ip':ip_address,'port':port})).encode('ascii'))
data = tracker_io.read_from_socket()
if (data == b''):
print('join result empty')
return None
response = json.loads(data.decode('utf-8'))
......@@ -91,7 +91,7 @@ class Server:
self._server_list = response.get('value')
print(self._server_list)
else:
print(response.get('description'))
print(response)
return None
# nanya ke server lain
......
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