Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sumo-user] Writing output to and receiving output on a socket
  • From: Michael Behrisch <oss@xxxxxxxxxxx>
  • Date: Fri, 29 Mar 2019 11:56:38 +0100
  • Autocrypt: addr=oss@xxxxxxxxxxx; prefer-encrypt=mutual; keydata= mQGiBFLSvucRBACGsasS4GeIWs1CFNTOYmp3ScQ2ZTJLJWQxhPliwtHTzLsErYu9Y7e8qDov iHFviYyaNuceUNoACm1e4MT4eu0DmM2Wk3y/jjD6hfm7L0EZNPxQhj+CJf2oZAm2ezCe7/si xZ2d7TCO8yWavOGbF0EVi/ZDIJqVgupu6WBpv/NCewCg65HQiS1wm+1w1MdFYxKCmXzbv08D /iWXX3tzabbCrLlUum8hBgBpJEHRtlic2uaGsKm8Fize4tfLZkTBbTYLYXfcx2Oq9+lINPTW h9jnbCjAjErRWLTjNTQjel0JnDryCnqabub/R3wScR/EHRDBeS9L6YRj0xdVd2qIaArtSYRR auKPNc4M2qZNEFSM37cXC7avhpdeA/99oJf4qyVly4RxHmekAmj9UJjRx17x9xX8t9uzUuSt AeTh+kQ3o5jK7veU6/F/+pPyi96EOzym9BJA8pgXC8hLWNjOajI10filkdQ26QsfHOpUdPSZ 4Duyw9Ayj8loagEnnAONmU/xE0QlyVBANIut0W+SNqPScYXfnBbVOaG3HbQiTWljaGFlbCBC ZWhyaXNjaCA8b3NzQGJlaHJpc2NoLmRlPohjBBMRAgAjBQJS0sHSAhsjBwsJCAcDAgEGFQgC CQoLBBYCAwECHgECF4AACgkQPBD+ltFwpimlmQCdGgnYuHxoye4vFntyHRcE0Ij0318AoN3s szGyKcKdUmPpgXLhFcNfRGe4uQENBFLSvucQBACRAt3OW7eL8N3OJp2bZz/rRldtxjcViEcd +wpQcL9Ag0b6W7e4cbSc9oSU9MAdOvxR0UxualeRGz37W/VEC8cFZb3kFtRdl66gGygKb7gl 2S27495XEYqE7BBF1HfQDjL9sh5GfuIzORkqhCHSUTdkRuzRPxNQcEYFSrASEi9jQwADBQP9 FeuTC1SJHrX9tP3p4xrEa07XkCq+UzwNhDdezoQfT1CUbOv+LT66yLTXAaiHXelgaPMQO1Oo 76U2z0C1LudkAcDdwJbMuZ0RfDoRjsgfhfvM6kqiP4m0s2NR3Y3O+HKXjwtPbXuDwaYIAIvp aj8b59n7fQyfL6BZsO0QZc0i/t+ISQQYEQIACQUCUtK+5wIbDAAKCRA8EP6W0XCmKY1lAKCc 3miJueOXuvZJWV7qGBQxxyR83gCgxhGPL9OrP22rxNJSo1w5OOUxHsM=
  • Delivered-to: sumo-user@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/sumo-user>
  • List-help: <mailto:sumo-user-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/sumo-user>, <mailto:sumo-user-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/sumo-user>, <mailto:sumo-user-request@eclipse.org?subject=unsubscribe>
  • Openpgp: preference=signencrypt
  • User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

Hi Peter,
this is not really a sumo specific question but I'll try to answer the
specific part. The sytax you are using tries to connect to a server
listening at the given address (on the given host). So you need to have
a listening server running there. The socket concept is not language
specific but if you want to see a python tutorial, try maybe this one:
https://www.binarytides.com/python-socket-programming-tutorial/

For the simplest case: opening a server socket, listening for only one
client and creating a file like object from it (which you can use to
read from like a file) the following should do:
    import socket
    port = 1338
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(("localhost", port))
    s.listen(1)
    conn, addr = s.accept()
    f = conn.makefile('rb')
(This code is also in tools/sumolib/miscutils.py, so feel free to use it
instead of reimplementing.)

Best regards,
Michael


Am 28.03.19 um 23:46 schrieb PETER MARCHIONE:
> Hello,
> 
> I've been given a task by my teammates involving SUMO. I need to figure
> out how to write information to a socket instead of a file. In pursuit
> of that goal, here's the command line I used.
> 
> "sumo -c hello.sumocfg ---netstate-dump localhost:1338"
> 
> Now that throws an error
> 
> "Error: tcpip::Socket::connect() @ connect: Socket refused (host:
> locahost, port: 1338)
> Qutting (on error).:
> 
> So my first problem is that I'm obviously not writing to the socket. I
> don't know if that's because it's not being given something to connect
> with, ie there's no listener on that socket. If that's the case, please
> let me know.
> 
> My second problem is that I don't know /how /to write something that
> listens on that socket and receives the data. To start off with, I would
> just like to write to a console all the information that it receives,
> that way I know it's receiving it. I don't know if asking for help on
> this is outside the scope of this mailing list, but if you have the
> time, any help would be appreciated.
> 
> Thanks,
> 
> Peter Marchione
> 
> _______________________________________________
> sumo-user mailing list
> sumo-user@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/sumo-user
> 


Attachment: signature.asc
Description: OpenPGP digital signature


Back to the top