Simple TCP/IP socket comunication wrapper between c++ and Python for IPC.
Project description
cpp_python_socket
Simple TCP/IP socket comunication wrapper between c++ and Python for IPC.
General Information
- Branch master covers simple string communication, relies on standard libraries.
- Branch image_transferring adds image transferring capabilities, relies on:
- OpenCV for c++:
https://github.com/opencv/opencvBuild
- OpenCV for Python:
pip install opencv-python
Only tested in Ubuntu 16.04, write an issue should you find any error.
Quick Start
- Either clone or add as a submodule this repo to your project folder:
git clone https://github.com/OleguerCanal/cpp_python_socket.git
or
git submodule add https://github.com/OleguerCanal/cpp_python_socket.git
- [OPTIONAL] Change branch to enable image transferring:
cd cpp_python_socket/
git checkout image_transferring
- If intending to use C++ code, add this 3 things to your CMakeLists.txt:
add_subdirectory(cpp_python_socket)
- Append
cpp_python_socket/cpp/include
toinclude_directories(...
- Append
cpp_sockets
totarget_link_libraries(...
of your library/executable.
Test the code
-
Change directory
cd cpp_python_socket/
-
Build it:
./build.sh
-
Run unit test:
- Terminal 1:
python python/server_unit_test.py
- Terminal 2:
cd cpp;
./run_cpp_client_test.sh
Usage examples
Python Server:
from cpp_python_socket.python.server import Server
if __name__ == "__main__":
server = Server("127.0.0.1", 5002)
# Check that connection works
message = server.receive()
print("[CLIENT]:" + message)
server.send("Shut up and send an image")
# Receive and show image
image = server.receive_image()
cv2.imshow('SERVER', image)
cv2.waitKey(1000)
server.send("Okioki")
C++ client:
#include <iostream>
#include "client.hpp"
int main() {
socket_communication::Client client("127.0.0.1", 5002);
// Check that connection works
client.Send("Hello hello!");
std::string answer = client.Receive();
std::cout << "Server: " << answer << std::endl;
// Load image and send image
cv::Mat img = cv::imread("cpp/lena.png");
client.SendImage(img);
std::string answer2 = client.Receive();
std::cout << "Server: " << answer2 << std::endl;
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for CppPythonSocket-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b5f796ff5bb84513f5b6f737b6e18ee3657bb2521a1056ee7441c298a0456cd |
|
MD5 | a91fb01177f800daca68745620437917 |
|
BLAKE2b-256 | bbb9dc0cbb2a0e11711881f34b02d6f03a7cc3613054d335d443d1094af89a29 |