项目作者: devlights

项目描述 :
Unix domain socket (UDS) examples by golang
高级语言: Go
项目地址: git://github.com/devlights/go-unix-domain-socket-example.git
创建时间: 2020-08-22T20:38:37Z
项目社区:https://github.com/devlights/go-unix-domain-socket-example

开源协议:MIT License

下载


go-unix-domain-socket-example

Unix domain socket (UDS) example by golang

How to Run

Using go-task

  1. $ task --list
  2. * run-basic: run basic example
  3. * run-readwrite: run readwrite example
  4. * run-readwrite2: run readwrite2 example
  5. * run-usinggob: run usinggob example
  6. $ task [run-basic|run-readwrite|run-readwrite2|run-usinggob]

basic

Open two terminals. the one is following:

  1. $ cd cmd/basic/server
  2. $ go run .

and another terminal is following:

  1. $ cd cmd/basic/client
  2. $ go run .

read & write per connection

Open two terminals. the one is following:

  1. $ cd cmd/readwrite/server
  2. $ go run .

and another terminal is following:

  1. $ cd cmd/readwrite/client
  2. $ go run .

N read & write on one connection

Open two terminals. the one is following:

  1. $ cd cmd/readwrite2/server
  2. $ go run .

and another terminal is following:

  1. $ cd cmd/readwrite2/client
  2. $ go run .

Using encoding/gob package

Open two terminals. the one is following:

  1. $ cd cmd/usinggob/server
  2. $ go run .

and another terminal is following:

  1. $ cd cmd/usinggob/client
  2. $ go run .

Monitor a local unix domain socket

use socat. install it if not exists.

  1. $ sudo apt install -y socat

and launch server program then input following commands.

  1. $ mv /tmp/echo.sock /tmp/echo.sock.original
  2. $ socat -t100 -x -v UNIX-LISTEN:/tmp/echo.sock,mode=777,reuseaddr,fork UNIX-CONNECT:/tmp/echo.sock.original

REFERENCES

Can I monitor a local unix domain socket like tcpdump?