简单的TCP/IP套接字在C++与Python之间的封装。
CppPythonSocket的Python项目详细描述
重要提示:这对我来说更像是学习如何制作可安装包的练习,而不是实际有用的包。它还没有完成,所以预计会有错误和很多丢失的东西。
cpp_python_套接字
用于IPC的C++和Python之间的简单TCP/IP套接字通信包装器。
一般信息
要安装C++包,请阅读/编辑源代码和更多信息,请查看repo: https://github.com/OleguerCanal/cpp_python_socket.git
用法示例
python服务器:
fromCppPythonSocketimportServerimportcv2if__name__=="__main__":server=Server("127.0.0.1",5002)# Check that connection worksmessage=server.receive()print("[CLIENT]:"+message)server.send("Shut up and send an image")# Receive and show imageimage=server.receive_image()cv2.imshow('SERVER',image)cv2.waitKey(1000)server.send("Thanks!")
C++客户端:
#include<iostream>#include"client.hpp"intmain(){socket_communication::Clientclient("127.0.0.1",5002);// Check that connection worksclient.Send("Hello hello!");std::stringanswer=client.Receive();std::cout<<"Server: "<<answer<<std::endl;// Load image and send imagecv::Matimg=cv::imread("cpp/lena.png");client.SendImage(img);std::stringanswer2=client.Receive();std::cout<<"Server: "<<answer2<<std::endl;}