title: Read data directly from /dev/log Unix Domain Socket
body: <p>My project aims at reading log messages directly from <code>/dev/log</code> UNIX domain socket in Java. Currently I am using <a href="https://code.google.com/p/junixsocket/" rel="nofollow noreferrer">junixsocket</a>. Below is a sample code of client that reads from a unix socket.</p>
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  
  import org.newsclub.net.unix.AFUNIXSocket;
  import org.newsclub.net.unix.AFUNIXSocketAddress;
  import org.newsclub.net.unix.AFUNIXSocketException;
  
  public class SimpleTestClient {
      public static void main(String[] args) throws IOException {
          final File socketFile = new File(&quot;/dev/log&quot;);
  
          AFUNIXSocket sock = AFUNIXSocket.newInstance();
          try {
              sock.connect(new AFUNIXSocketAddress(socketFile));
          } catch (AFUNIXSocketException e) {
              System.out.println(&quot;Cannot connect to server. Have you started it?\n&quot;);
              System.out.flush();
              throw e;
          }
          System.out.println(&quot;Connected&quot;);
  
          InputStream is = sock.getInputStream();
  
          byte[] buf = new byte[8192];
  
          int read = is.read(buf);
          System.out.println(&quot;Server says: &quot; + new String(buf, 0, read));
      
          is.close();
  
          sock.close();
  
          System.out.println(&quot;End of communication.&quot;);
      }
  }
  </code></pre>
  <p>The above mentioned code is unable to connect to <code>/dev/log</code>. It throws an exception:</p>
  <pre><code>Cannot connect to server. Have you started it?
  Exception in thread &quot;main&quot; org.newsclub.net.unix.AFUNIXSocketException: Protocol wrong type for socket (socket: /dev/log)
          at org.newsclub.net.unix.NativeUnixSocket.connect(Native Method)
          at org.newsclub.net.unix.AFUNIXSocketImpl.connect(AFUNIXSocketImpl.java:125)
          at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:97)
          at org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:87)
          at SimpleTestClient.main(SimpleTestClient.java:40)
  </code></pre>
  <p>I am unable to figure out how to solve this problem. Any help would be appreciable.</p>