I intend to establish Socket connection in spout. Here is my code :

@Override
public void nextTuple() {
    Socket socket = null;
    try {
        socket = serverSocket.accept();
    } catch (IOException e) {
        e.printStackTrace();
    }
    TCPReceiver tcpReceiver = new TCPReceiver(socket,inQueue);
    //disable thread to send the string immediately
    tcpReceiver.receiveData();
    if (!inQueue.isEmpty()){
        String readyString = inQueue.poll();
        _collector.emit(new Values(readyString));
    }
}

 

The nextTuple() is blocked until new socket is established. It works under
LocalCluster mode, but in production envirionment, tcp client cannot connect
to this socket server. I use the command “nc -l 20000”(my listening port
is 20000) while the program is running, it can receive the data from tcp
client. Can any one help me? Thanks 

 

Regard, 

Junfeng Chen(陈俊峰)

 

Reply via email to