84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
I would like to ask what the .sock file is used for. I have no idea at all. . .
认证高级PHP讲师
means.sock为后缀的文件而已。UNIX 系统不以后缀区分文件类型,但为了方便,通常使用后缀来标识一下。.sock文件极有可能是UNIX 域套接字(UNIX domain socket),即通过文件系统(而非网络地址)进行寻址和访问的套接字。参见 man 手册 unix(7)(命令:man 7 unix).
.sock
man 7 unix
Unix domain sockethttp://en.wikipedia.org/wiki/Unix_domain_socket
The opposite is tcp sockthttp://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html
Example (golang):From this
server.go
package main import "net" func echoServer(c net.Conn) { for { buf := make([]byte, 512) nr, err := c.Read(buf) if err != nil { return } data := buf[0:nr] println("Server got:", string(data)) _, err = c.Write(data) if err != nil { panic("Write: " + err.Error()) } } } func main() { l, err := net.Listen("unix", "/tmp/echo.sock") if err != nil { println("listen error", err.Error()) return } for { fd, err := l.Accept() if err != nil { println("accept error", err.Error()) return } go echoServer(fd) } }
client.go
package main import ( "io" "net" "time" ) func reader(r io.Reader) { buf := make([]byte, 1024) for { n, err := r.Read(buf[:]) if err != nil { return } println("Client got:", string(buf[0:n])) } } func main() { c, err := net.Dial("unix", "/tmp/echo.sock") if err != nil { panic(err.Error()) } defer c.Close() go reader(c) for { _, err := c.Write([]byte("hi....")) if err != nil { println(err.Error()) break } time.Sleep(1e9) } }
When running the server, the /tmp/echo.sock file will be suggested
means
.sock
为后缀的文件而已。UNIX 系统不以后缀区分文件类型,但为了方便,通常使用后缀来标识一下。.sock
文件极有可能是UNIX 域套接字(UNIX domain socket),即通过文件系统(而非网络地址)进行寻址和访问的套接字。参见 man 手册 unix(7)(命令:man 7 unix
).Unix domain socket
http://en.wikipedia.org/wiki/Unix_domain_socket
The opposite is tcp sockt
http://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html
Example (golang):
From this
server.go
client.go
When running the server, the /tmp/echo.sock file will be suggested