Hi mina-users,
new to mina, I have a problem sending a message. I copied code from one
of our 2.0 tutorials, but the message I try to send via TCP is not sent.
The receiver part works - tested via telnet connection.
I'm wondering, why the IOHandler.messageSent method is never called.
Do you have an idea what's going wrong?
Thank you,
Thomas
---code ---
import java.net.InetSocketAddress;
import org.apache.mina.core.future.CloseFuture;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
public class TestClient {
private static final int PORT = 50001;
/**
* @param args
*/
public static void main(String[] args) {
IoConnector connector = new NioSocketConnector();
connector.setHandler(new IoHandler() {
@Override
public void sessionOpened(IoSession arg0) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void sessionIdle(IoSession arg0, IdleStatus arg1)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public void sessionCreated(IoSession arg0) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void sessionClosed(IoSession arg0) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void messageSent(IoSession arg0, Object arg1) throws
Exception {
// TODO Auto-generated method stub
System.out.println("I sent a message");
}
@Override
public void messageReceived(IoSession arg0, Object arg1)
throws Exception {
// TODO Auto-generated method stub
}
@Override
public void exceptionCaught(IoSession arg0, Throwable arg1)
throws Exception {
// TODO Auto-generated method stub
}
} );
ConnectFuture future = connector.connect(
new InetSocketAddress("localhost", PORT));
IoSession session;
try {
session = future.await().getSession();
System.out.println(session);
System.out.println("writing to session...");
session.write("Test").await(); // WriteFuture
System.out.println("wrote to session");
//close up session
CloseFuture cfuture = session.close(true);
// Wait until the connection is closed
cfuture.awaitUninterruptibly();
// Now connection should be closed.
System.out.println("session closed now");
assert cfuture.isClosed();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}