Rpc's request response is through the tcp protocol, and the service broadcast uses the udp protocol. We only need to implement the network protocol.

PHP sample code

 * Created by PhpStorm.
 * User: xcg
 * Date: 2019/6/17
 * Time: 14:30
$data = [
    'command' => 1,//1:Request, 2: status rpc status of each service
    'request' => [
        'serviceName' => 'UserService',
        'action' => 'register',//Behavior name
        'arg' => [
            'args1' => 'args1',
            'args2' => 'args2'

//$raw = serialize($data);//Note the serialization type, you need to agree with the RPC server agreement $serializeType


$fp = stream_socket_client('tcp://');
fwrite($fp, pack('N', strlen($raw)) . $raw);//Pack data check

$data = fread($fp, 65533);
//Length check
$len = unpack('N', $data);
$data = substr($data, '4');
if (strlen($data) != $len[1]) {
    echo 'data error';
} else {
    $data = json_decode($data, true);
    // This is the result returned by the server.,
    var_dump($data); // By default, a response object will be returned. Modify by $serializeType

Go sample code

package main

import (

func main() {
    var tcpAddr *net.TCPAddr
    tcpAddr,_ = net.ResolveTCPAddr("tcp","")
    conn,_ := net.DialTCP("tcp",nil,tcpAddr)
    defer conn.Close()

func sendEasyswooleMsg(conn *net.TCPConn) {
    var sendData []byte
    data := `{"command":1,"request":{"serviceName":"UserService","action":"register","arg":{"args1":"args1","args2":"args2"}}}`
    b := []byte(data)
    // The big endian (network byte order) big end is to put the high byte to the low address end of the memory, and the low byte to the high address end.
    // In the network transmission (such as TCP/IP), the low address end (high byte) is placed at the beginning of the stream. For the 2-byte string (AB), the transmission order is:A(0-7bit)、B(8-15bit)。
    sendData = int32ToBytes8(int32(len(data)))
    // Assemble the data byte to the back of sendData
    for _, value := range b {
        sendData = append(sendData, value)

func int32ToBytes8(n int32) []byte {
    var buf = make([]byte, 4)
    binary.BigEndian.PutUint32(buf, uint32(n))
    return buf



public class Main {
    public static void main(String[] args) throws IOException {
        byte[] msg = "{\"command\":1,\"request\":{\"serviceName\":\"UserService\",\"action\":\"register\",\"arg\":{\"args1\":\"args1\",\"args2\":\"args2\"}}}".getBytes();
        byte[] head = Main.toLH(msg.length);
        byte[] data = Main.mergeByteArr(head, msg);

        //Create a Socket object and connect to the server
        Socket socket=new Socket("",9600);
        //Get the byte output stream and write the data to the server through the socket object Socket method of the client.
        OutputStream out=socket.getOutputStream();

        //Read the data sent back by the server, using the byte input stream in the socket socket object
        InputStream in=socket.getInputStream();
        byte[] response=new byte[1024];
        System.out.println(new String(response,4, len-4));

    static byte[] toLH(int n) {
        byte[] b = new byte[4];
        b[3] = (byte) (n & 0xff);
        b[2] = (byte) (n >> 8 & 0xff);
        b[1] = (byte) (n >> 16 & 0xff);
        b[0] = (byte) (n >> 24 & 0xff);
        return b;

    static byte[] mergeByteArr(byte[] a, byte[] b) {
        byte[] c= new byte[a.length + b.length];
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(b, 0, c, a.length, b.length);
        return c;

Other languages only need to implement the tcp protocol.