Discussion:
[SimPy] Server/Client problem
Jorge Velásquez
2015-05-12 13:28:58 UTC
Permalink
Hello!

I am using an example from the simpy.io 0.2.1 documentation in order to
define a client that sends messages. The code that I am using is listed
below:

from simpy.io import select as backend
from simpy.io.packet import PacketUTF8
from simpy.io.message import Message

def client(env, addr):
sock = backend.TCPSocket.connection(env, addr)
print('client connected to', sock.peer_address)
message = Message(env, PacketUTF8(sock))
print('client receiving ...')
req = yield message.recv()
print('client received req:', req.content)
yield req.succeed('whatever')
print('client done')

addr = ('xxx.xx.xx.xxx', 4444)

def main():
env = backend.Environment()
cli = env.process(client(env, addr))
env.run(until=cli)

if __name__ == '__main__':
main()

In addition I am using the following code in order to send and receive
information.

from simpy.io import select as backend
from simpy.io.packet import PacketUTF8 as Packet
from simpy.io.message import Message

ADDR = 'xxx.xx.xx.xxx:4444'

def dummyproc(env, server_socket):
print('Server is listening at ', ADDR)
sock = yield server_socket.accept()
print('Server Accept', sock.peer_address)
message = Message(env, Packet(sock, max_packet_size=10e6*1024))

content = ['init', ['ExampleSim-0'], {'step_size': 2}]
print('Server sending: ', content)
reply = yield message.send(content)
print('Server received', reply)

def main():

env = backend.Environment()
addr = ADDR.split(':')
addr = (addr[0], int(addr[1]))
print('Server started...')
server_socket = backend.TCPSocket.server(env, addr)

end = env.process(dummyproc(env, server_socket))
env.run(until=end)

print('Server socket closed')
server_socket.close()

if __name__ == '__main__':
main()


When I run this in the local host everything works without problems. In
contrast, I have an error message when I try to connect to an external IP
address on a different machine. The error messages I get are listed as
follows.


C:\Users\jvelasquez\Envs\mosaik\Scripts\python.exe
C:/Users/jvelasquez/PycharmProjects/untitled/SimpyIO_Example.py
Traceback (most recent call last):
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\select.py",
line 61, in _do_read
self._reader._value = self.sock.recv(self._reader.amount)
OSError: [WinError 10057] A request to send or receive data was disallowed
because the socket is not connected and (when sending on a datagram socket
using a sendto call) no address was supplied

*From the client side:*

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\message.py",
line 98, in _reader
client connected to ('xxx.xx.xx.xxx', 4444)
client receiving ...
self._handle_error(self.reader, e)
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\message.py",
line 143, in _handle_error
raise err
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\message.py",
line 70, in _reader
data = yield self.socket.read()
OSError: [WinError 10057] A request to send or receive data was disallowed
because the socket is not connected and (when sending on a datagram socket
using a sendto call) no address was supplied

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:/Users/jvelasquez/PycharmProjects/untitled/SimpyIO_Example.py",
line 25, in <module>
main()
File "C:/Users/jvelasquez/PycharmProjects/untitled/SimpyIO_Example.py",
line 22, in main
env.run(until=cli)
File "C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\core.py",
line 137, in run
self.step()
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\base.py", line
77, in step
callback(event)
File "C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\core.py",
line 59, in callback
raise event.value
File "C:/Users/jvelasquez/PycharmProjects/untitled/SimpyIO_Example.py",
line 10, in client
req = yield message.recv()
OSError: [WinError 10057] A request to send or receive data was disallowed
because the socket is not connected and (when sending on a datagram socket
using a sendto call) no address was supplied

Process finished with exit code 1

*From the server side:*

Server started...
Server is listening at xxx.xx.xx.xxx:4444
Server Accept ('xxx.xx.xxx.x', 60004)
Server sending: ['init', ['ExampleSim-0'], {'step_size': 2}]
Traceback (most recent call last):
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\select.py", l
ine 61, in _do_read
self._reader._value = self.sock.recv(self._reader.amount)
ConnectionResetError: [WinError 10054] Eine vorhandene Verbindung wurde vom
Remo
tehost geschlossen

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\message.py",
line 98, in _reader
self._handle_error(self.reader, e)
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\message.py",
line 143, in _handle_error
raise err
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\message.py",
line 70, in _reader
data = yield self.socket.read()
ConnectionResetError: [WinError 10054] Eine vorhandene Verbindung wurde vom
Remo
tehost geschlossen

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "MosaikDummy.py", line 38, in <module>
main()
File "MosaikDummy.py", line 31, in main
env.run(until=end)
File "C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\core.py",
line 1
37, in run
self.step()
File
"C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\io\base.py", lin
e 77, in step
callback(event)
File "C:\Users\jvelasquez\Envs\mosaik\lib\site-packages\simpy\core.py",
line 5
9, in callback
raise event.value
File "MosaikDummy.py", line 18, in dummyproc
reply = yield message.send(content)
ConnectionResetError: [WinError 10054] Eine vorhandene Verbindung wurde vom
Remo
tehost geschlossen

Could you please give me some pointers to solve this problems? Any idea
what might be wrong?

I appreciate your help,
--
Best regards,

Jorge
Ontje Lünsdorf
2015-05-13 06:59:24 UTC
Permalink
Hi Jorge,
Post by Jorge Velásquez
Could you please give me some pointers to solve this problems? Any idea
what might be wrong?
I vaguely remember that simpy.io 0.2.1 might assume that connections are always immediately successful or fail. Please try the attached patch. It would also be nice if you create an issue at https://bitbucket.org/simpy/simpy.io/issues and report back with your findings.

Thanks,
Ontje

Loading...