Git Product home page Git Product logo

scoml's Introduction

socket communication over multi-languages

You can use it to communication over multi-languages very simply. For example, the communication between Python and C++ when using C++ sending an image to Python classification model and receiving the result. In this case, make a server using Python and using C++ code as a client to send image and receive answer. You can simply using the following code to implement it.

message structure

data

example1

data

example2

data

  1. Simple. both send and received messages are bytes.

  2. Default maximal 999999999999 Bytes message body, that is maximum 931.3GB in one send or receive. You also can increase the ori_len(oriLen) parameter to support more data transfer at a time.

  3. Only tested on Ubuntu18.04, and it should be run well on unix-like systems.

  4. Code on other language is comming.

Usage

Server

Python3

from scomlVarSocket import ScomlServerSocket

class Handler(ScomlServerSocket):
    def response(self, msg):
        # You should write your execute code here.
        print("received msg ", msg)
        return b'abc'

hand = Handler()
hand.start(12000)

C++

C++11 above

#include <string>                                                                                               
#include <iostream>                                                                                             
#include"scomlVarSocket.h"                                                                                          
                                                                                                                
std::string scoml::ServerSocket::response(std::string &msg){
    // You should write your execute code here.
    std::string answer += "abc";
    return answer; 
                                                                                                                
int main(){ 
    std::string ip("localhost");
    std::string port("12000");
    scoml::ServerSocket server(ip, port);
    server.start(); 
    return 0;
}

Client

Python3

from scomlVarSocket import scoml_var_request
answer = scoml_var_request("localhost", 12000, message= "hello world")
print(answer)

C++

C++11 above

#include <string>
#include <iostream>
#include "scomlVarSocket.h"

int main(){
std::string ip("localhost");
std::string port("12000"); 
std::string msg("abc"); 
std::string answer = scoml::var_request(ip, port, msg);
std::cout << answer << std::endl;
return 0;

scoml's People

Contributors

springtime-cn avatar

Stargazers

 avatar Suraj Joshi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.