import java.io.File; import java.io.IOException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TFastFramedTransport; import org.apache.thrift.transport.TIOStreamTransport; import org.apache.thrift.transport.TTransport; import org.newsclub.net.unix.AFUNIXServerSocket; import org.newsclub.net.unix.AFUNIXSocket; import org.newsclub.net.unix.AFUNIXSocketAddress; public class ThriftUnixDomainSocketServer { public static void main(String[] args) throws IOException { File socketFile = new File("thrift.sock"); if (socketFile.exists()) socketFile.delete(); AFUNIXServerSocket serverSocket = AFUNIXServerSocket.newInstance(); serverSocket.bind(new AFUNIXSocketAddress(socketFile)); AFUNIXSocket socket = (AFUNIXSocket) serverSocket.accept(); TTransport ttransport = new TFastFramedTransport(new TIOStreamTransport(socket.getInputStream(), socket.getOutputStream())); TProtocol tprotocol = new TBinaryProtocol(ttransport); // tprotocol is ready to use! } }