简体   繁体   English

UDT C ++库的Python包装器

[英]Python wrapper for UDT C++ library

I want to use the UDT library in Python, so I need a wrapper. 我想在Python中使用UDT库 ,所以我需要一个包装器。 I found this one: pyudt , but I dont know exactly how to use this to send files from a peer to peer. 我找到了这个: pyudt ,但我不确切知道如何使用它来发送来自对等的文件。 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: 安装pyudt-0.1a的步骤如下:

  • install: libboost-python1.46-dev or equivalent (for instance, in linux-ubuntu12.04 it's in the reps.) 安装:libboost-python1.46-dev或等效的(例如,在linux-ubuntu12.04中,它位于代表中。)

  • install udt.h (from: http://sourceforge.net/projects/udt/ ) into a system directory, 将udt.h(来自: http//sourceforge.net/projects/udt/ )安装到系统目录中,

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: (将udt.h文件放在与pyudt-0.1a文件相同的路径中,然后从以下位置更改“pyudt.cpp”的一行:

#include <udt.h>

to: 至:

#include "udt.h"

). )。

  • update the version of boost_python library, in "setup.py" to the one you're using, 将“setup.py”中的boost_python库版本更新为您正在使用的版本

eg.: 例如。:

    ... libraries=['udt', 'boost_python-py27'])
  • change the following line(s) in "pyudt.cpp": 更改“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. 因为字符“\\ 0”表示字符串的结尾也必须发送,否则垃圾将附加到您的字符串。

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! 它工作,它与我的cpp服务器谈话!

notice: if you need more help you can write in the python's console: 注意:如果您需要更多帮助,可以在python的控制台中编写:

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

PS. 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 使用此安装教程创建的文件是:/usr/local/lib/python2.7/dist-packages/pyudt.so,/usr/local/lib/python2.7/dist-packages/pyudt-0.1a.egg -信息

You can give my udt_py fork a try. 你可以尝试一下我的udt_py fork It includes a sample recvfile.py now and can retrieve files from the sendfile daemon in udt's app directory. 它现在包含一个示例recvfile.py ,可以从udt的app目录中的sendfile守护进程中检索文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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