Re: Socket and cycle problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: Socket and cycle problem

    On Mon, 12 May 2008 09:19:48 -0700 (PDT), petr.poupa@gmai l.com wrote:
    >
    [snip]
    >>
    >Where is the mistake? I dont know.
    >>
    >You cannot reconnect a socket. You need to create a new one for each
    >connection. It's also almost certainly the case that the way you are
    >receiving data is incorrect. There is no guarantee that you will get
    >2048 bytes from socket.recv(204 8). It isn't even guaranteed that all
    >the bytes written to the socket by the peer will be returned by such
    >a call. Instead, you need a framing protocol to determine when all
    >data has been received. For example, you might length prefix the
    >data, or you might insert a delimiter (or a terminator) at the end. Or
    >if there is exactly one message to receive, then you should just read
    >until the recv call returns '', indicating EOF.
    >>
    >Jean-Paul
    >
    >ok thanks, but I am true greenhorn, so you think that the best way is
    >write new script?
    >Could you send me code if it isnt long, becase I have no idea and
    >unfortunatel y time as well.
    >
    I'm not sure what you want to happen, so I can't write it for you. I
    suggest you start with Twisted instead of the socket module, though,
    as Twisted provides a higher-level interface to network programming.

    You can find some introductory documentation about writing clients here:



    Jean-Paul
  • petr.poupa@gmail.com

    #2
    Re: Socket and cycle problem

    On 12 Kvì, 19:16, Jean-Paul Calderone <exar...@divmod .comwrote:
    On Mon, 12 May 2008 09:19:48 -0700 (PDT), petr.po...@gmai l.com wrote:
    >
    [snip]
    >
    Where is the mistake? I dont know.
    >
    You cannot reconnect a socket. You need to create a new one for each
    connection. It's also almost certainly the case that the way you are
    receiving data is incorrect. There is no guarantee that you will get
    2048 bytes from socket.recv(204 8). It isn't even guaranteed that all
    the bytes written to the socket by the peer will be returned by such
    a call. Instead, you need a framing protocol to determine when all
    data has been received. For example, you might length prefix the
    data, or you might insert a delimiter (or a terminator) at the end. Or
    if there is exactly one message to receive, then you should just read
    until the recv call returns '', indicating EOF.
    >
    Jean-Paul
    >
    ok thanks, but I am true greenhorn, so you think that the best way is
    write new script?
    Could you send me code if it isnt long, becase I have no idea and
    unfortunately time as well.
    >
    I'm not sure what you want to happen, so I can't write it for you. I
    suggest you start with Twisted instead of the socket module, though,
    as Twisted provides a higher-level interface to network programming.
    >
    You can find some introductory documentation about writing clients here:
    >

    >
    Jean-Paul

    My script send me via 3883 port (VRPN) data, but only once. I need
    listening this port countinously.
    So I need make some loop to print data from 3883 port permanent.
    Data that I recevied looks liek this:

    receive data from server: 'vrpn: ver. 07.13 0\x00\xe8\x0b\x 00\x00'

    Do you think its necessary to use Twisted? Do you have any ideas how
    to do it with socket modul?

    thanks for reply

    Comment

    Working...