Socket and cycle problem

petr.poupa at gmail.com petr.poupa at gmail.com
Mon May 12 14:16:08 EDT 2008


On 12 Kvě, 19:16, Jean-Paul Calderone <exar... at divmod.com> wrote:
> On Mon, 12 May 2008 09:19:48 -0700 (PDT), petr.po... at gmail.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(2048).  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:
>
>  http://twistedmatrix.com/projects/core/documentation/howto/clients.html
>
> 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\x00\x00'

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

thanks for reply



More information about the Python-list mailing list