简体   繁体   中英

Python wrapper for UDT C++ library

I want to use the UDT library in Python, so I need a wrapper. I found this one: pyudt , but I dont know exactly how to use this to send files from a peer to peer. Can anybody point me in the right direction?

after so many time I've found this question and its solution:

The steps to install pyudt-0.1a are:

  • install: libboost-python1.46-dev or equivalent (for instance, in linux-ubuntu12.04 it's in the reps.)

  • install udt.h (from: http://sourceforge.net/projects/udt/ ) into a system directory,

OR
(put the udt.h file in the same path as the pyudt-0.1a files, and then change a line of the "pyudt.cpp", from:

#include <udt.h>

to:

#include "udt.h"

).

  • update the version of boost_python library, in "setup.py" to the one you're using,

eg.:

    ... libraries=['udt', 'boost_python-py27'])
  • change the following line(s) in "pyudt.cpp":

you must correct a bug, changing from:

int r = UDT::send(_sock, data.c_str(), data.length(), 0);

to:

int r = UDT::send(_sock, data.c_str(), data.length()+1, 0);

because the character "\\0" meaning the end of string must also be sent, otherwise junk would be appended to your string.

optionally, you may choose between:

   _sock = UDT::socket(AF_INET, SOCK_DGRAM, 0);   --» default

or:

   _sock = UDT::socket(AF_INET, SOCK_STREAM, 0);  --» optional
  • finally, run,

in the corresponding folder:

python2.7 ./setup.py build
sudo python2.7 ./setup.py install

OR, (if you don't have admin permissions to install it for all the users, and just wanna try it for you:

python2.7 ./setup.py build
python2.7 ./setup.py install --prefix=~/pyudt-0.1a/installation_dir/  #in this case, pyudt would only work if called from that directory

)

Then, the code for a simple client can be:

import pyudt
socket = pyudt.pyudt_socket()
socket.connect(("127.0.0.1", 7000))
socket.send("hello_world!")

and it works, it talks with my cpp server!

notice: if you need more help you can write in the python's console:

import pyudt
dir(pyudt.pyudt_socket) # to list the available functions
help(pyudt)             # to get more help

PS. the files created with this installation tutorial are: /usr/local/lib/python2.7/dist-packages/pyudt.so, and /usr/local/lib/python2.7/dist-packages/pyudt-0.1a.egg-info

You can give my udt_py fork a try. It includes a sample recvfile.py now and can retrieve files from the sendfile daemon in udt's app directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM