Transport

rpcx can commnunicate via TCP, HTTP Connect, UnixDomain, QUIC and KCP. You can also access rpcx by a http client via Gateway or HTTP_Invoke.

TCP

It is the most used transport. High performance and easy. You can use TLS for TCP security.

Example:101basic

Servers use tcp as network name and they registers services asserviceName/tcp@ipaddress:port in the registry.```go server.gos.Serve("tcp", *addr)

  1. Client can access services by:
  2. ```go
  3. d := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
  4. xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
  5. defer xclient.Close()

HTTP Connect

You can send HTTP CONNECT method to rpcx servers. Rpcx servers hijacks this connection and use it as a TCP connection.Notice clients and servers don't use http requests/responses to communicate and they still use the binary protocol based on this connection.

The network name is http and the registered format is serviceName/http@ipaddress:port

It is not recommended and TCP is the first choice.

If you want to use http requests/responses to access, you should use gateway or http_invoke.

Unixdomain

the network name is unix.

Example:unix

QUIC

From wikipedia

QUIC (Quick UDP Internet Connections, pronounced quick) is an experimental transport layer network protocol designed by Jim Roskind at Google, initially implemented in 2012, and announced publicly in 2013 as experimentation broadened. QUIC supports a set of multiplexed connections between two endpoints over User Datagram Protocol (UDP), and was designed to provide security protection equivalent to TLS/SSL, along with reduced connection and transport latency, and bandwidth estimation in each direction to avoid congestion. QUIC's main goal is to improve perceived performance of connection-oriented web applications that are currently using TCP. It also moves control of the congestion avoidance algorithms into the application space at both endpoints, rather than the kernel space, which it is claimed will allow these algorithms to improve more rapidly.In June 2015, an Internet Draft of a specification for QUIC was submitted to the IETF for standardization. A QUIC working group was established in 2016. The QUIC working group foresees multipath support and optional forward error correction (FEC) as the next step. The working group also focuses on network management issues that QUIC may introduce, aiming to produce an applicability and manageability statement in parallel to the actual protocol work. Internet statistics in 2017 suggest that QUIC now accounts for more than 5% of Internet traffic.

the network name is quic.

Example:quic

KCP

KCP is a fast and reliable ARQ protocol.

the network is kcp.

Example:kcp

reuseport

the network name is reuseport.

Example:reuseport

It uses tcp protocol and set SO_REUSEPORT socket option for linux and unix servers.

TLS

Example:TLS

You can set TLS in server:

  1. func main() {
  2. flag.Parse()
  3. cert, err := tls.LoadX509KeyPair("server.pem", "server.key")
  4. if err != nil {
  5. log.Print(err)
  6. return
  7. }
  8. config := &tls.Config{Certificates: []tls.Certificate{cert}}
  9. s := server.NewServer(server.WithTLSConfig(config))
  10. s.RegisterName("Arith", new(example.Arith), "")
  11. s.Serve("tcp", *addr)
  12. }

And set TLS in client:

  1. func main() {
  2. flag.Parse()
  3. d := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
  4. option := client.DefaultOption
  5. conf := &tls.Config{
  6. InsecureSkipVerify: true,
  7. }
  8. option.TLSConfig = conf
  9. xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, option)
  10. defer xclient.Close()
  11. args := &example.Args{
  12. A: 10,
  13. B: 20,
  14. }
  15. reply := &example.Reply{}
  16. err := xclient.Call(context.Background(), "Mul", args, reply)
  17. if err != nil {
  18. log.Fatalf("failed to call: %v", err)
  19. }
  20. log.Printf("%d * %d = %d", args.A, args.B, reply.C)
  21. }

By smallnest updated 2018-12-04 11:47:26