use-net-unixconn

command
v0.5.38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2025 License: MIT Imports: 9 Imported by: 0

README

UNIXドメインソケットの抽象名前空間のサンプル (net-unixconn版)

Linux特有の機能である「抽象名前空間」(Abstract Namespace)のUnixドメインソケットは以下の特徴がある

  • ソケットのアドレス(名前)の先頭にNULバイト(\0)を付ける
  • ファイルシステム上にソケットファイルを作成しない
  • プロセス終了時に自動的にクリーンアップされる

netパッケージで利用する場合、アドレスの先頭に @ を付与しておくと、内部で NULバイト(\0) に置き換えてくれる。

実行例

$ task
task: [build] go build -o app main.go
task: [run] ./app -server &
task: [run] sleep 1
task: [run] ./app
09:01:13.238544 [C] Send (hello)
09:01:13.239925 [S] Recv (hello)
09:01:13.240143 [S] Send (HELLO)
09:01:13.240205 [C] Recv (HELLO)
09:01:13.240314 [S] disconnect
task: [run] pkill -f './app -server' || true

参考情報

Documentation

Overview

UNIXドメインソケット 抽象名前空間のサンプル(netパッケージのUnixConnを利用する版)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL