use of net.i2p.client.I2PSessionListener in project i2p.i2p-bote by i2p.
the class Ping method listen.
private void listen() throws Exception {
System.out.println("Listening for pings on I2P destination " + Util.toBase32(i2pSession.getMyDestination()) + ".b32.i2p");
i2pSession.addSessionListener(new I2PSessionListener() {
private int count;
@Override
public void reportAbuse(I2PSession session, int severity) {
}
@Override
public void messageAvailable(I2PSession session, int msgId, long size) {
try {
count++;
byte[] payload = session.receiveMessage(msgId);
String sender = new String(Arrays.copyOf(payload, 60));
System.out.println("#" + count + " " + new Date() + " sender=" + sender + " length=" + payload.length + " bytes");
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void errorOccurred(I2PSession session, String message, Throwable error) {
error.printStackTrace();
}
@Override
public void disconnected(I2PSession session) {
System.err.println("Disconnected!");
}
}, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_ANY);
// wait forever
new CountDownLatch(1).await();
}
Aggregations