Skip to content

Instantly share code, notes, and snippets.

@qerub
Created June 23, 2013 22:03
Show Gist options
  • Save qerub/5846713 to your computer and use it in GitHub Desktop.
Save qerub/5846713 to your computer and use it in GitHub Desktop.
Thrift + Unix domain socket server
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!
}
}
@rameshpasunoori
Copy link

Hi

If it's possible can you provide the complete example.
I am new to java and need to complete this task ASAP.

Thanks
Ramesh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment