jnr / jnr-unixsocket

UNIX domain sockets (AF_UNIX) for Java
Apache License 2.0
278 stars 75 forks source link

Exception in thread "main" java.io.IOException: Protocol wrong type for socket #56

Closed CAFEBABE88 closed 6 years ago

CAFEBABE88 commented 6 years ago

I use jnr-unixsocket v0.18 under linux like this:

File path = new File("/var/run/test.sock");
UnixSocketAddress address = new UnixSocketAddress(path);
UnixSocketChannel channel = UnixSocketChannel.open(address);

but get an exception:

Exception in thread "main" java.io.IOException: Protocol wrong type for socket at jnr.unixsocket.UnixSocketChannel.doConnect(UnixSocketChannel.java:127) at jnr.unixsocket.UnixSocketChannel.connect(UnixSocketChannel.java:136) at jnr.unixsocket.UnixSocketChannel.open(UnixSocketChannel.java:68)

CAFEBABE88 commented 6 years ago

the reason is my server's socket type is SOCK_DGRAM but not SOCK_STREAM, after changing the socket type to SOCK_STREAM, this problem is solved.