Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Support Unix Domain Sockets #909

Closed
1 task done
F1bonacc1 opened this issue Apr 4, 2024 · 4 comments
Closed
1 task done

[FEATURE] Support Unix Domain Sockets #909

F1bonacc1 opened this issue Apr 4, 2024 · 4 comments

Comments

@F1bonacc1
Copy link

F1bonacc1 commented Apr 4, 2024

Is there an existing feature request for this?

  • I have searched the existing feature requests

Is your feature request related to a problem? Please describe.

Using UNIX Domain Sockets (UDS) allows more flexibility in avoiding multiple projects (on the same host) collisions.
See here: F1bonacc1/process-compose#172

Describe the solution that you would like.

I am planning to implement both port and UDS based communication.
A user flag will select this.
I would like to be able to do something along the following lines:

var ws *websocket.Conn
if UDS {
  ws, _, err = websocket.DefaultDialer.DialUnix("ws://unix/hello", "/tmp/path.sock", nil)
}else{
  ws, _, err = websocket.DefaultDialer.Dial("ws://localhost:8080/hello", nil)
}
ws.WriteMessage(...)

Describe alternatives you have considered.

No response

Anything else?

No response

@F1bonacc1
Copy link
Author

Hey @GreenMarmot,
Thanks for the quick response.
The Dialer.NetDialContext returns *net.Conn while the API works with *wbsocket.Conn. Is there a way to bridge or convert those?

@jaitaiwan
Copy link

wbsock.Conn contains a net.Conn

@F1bonacc1
Copy link
Author

Yes, there is a private method newCon that receives net.Conn and returns websocket.Conn.

@F1bonacc1
Copy link
Author

OK Figured it out:

d := websocket.Dialer{
	NetDialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
		return (&net.Dialer{}).DialContext(ctx, "unix", "/tmp/process-compose.sock")
	},
}
ws, _, err := d.Dial("ws://unix/hello", nil)

Maybe it will be useful to someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants