users@grizzly.java.net

Need help to get UDP client working

From: Johan Maasing <johan_at_zoom.nu>
Date: Sun, 9 Jun 2013 15:44:23 +0200

Hi,
I'm struggling (new to Grizzly) to get UDP traffic going between a server
and client. Currently I'm stuck at getting the client to send.I hope
someone can spot what I'm doing wrong.


This is the client code:
----
protected void startUp() throws Exception {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
 // Extends BaseFilter, logs which method got called and returns
super.handleXXX
filterChainBuilder.add(new LoggingFilter("Client " + protocol));
// Serializes java classes to byte[], logs the number of bytes
filterChainBuilder.add(new SerializableFilter());
 this.udpTransport = UDPNIOTransportBuilder.newInstance().build();
udpTransport.setProcessor(udpFilterChainBuilder.build());
udpTransport.start();
final GrizzlyFuture<Connection> udpConn = udpTransport.connect(new
InetSocketAddress(serverAddress, udpPort));
this.udpConnection = checkNotNull(udpConn.get(10, TimeUnit.SECONDS));
log.debug("Connections to server UDP: {}", this.udpConnection);
}
public void sendMessage(final MessageStruct message) throws
CommunicationException {
log.trace("Sending message {} to server", message);
udpConnection.write(message);
}
----
These are my log messages from the client:
----
Connections to server UDP: UDPNIOConnection{localSocketAddress={/
127.0.0.1:59296}, peerSocketAddress={/127.0.0.1:9667}}
Sending message n.z.c.c.m.JoinServerRequestMessage_at_1675bb28 to server
n.z.c.c.g.SerializableTransformer - Serializing
nu.zoom.corridors.connect.messages.JoinServerRequestMessage_at_1675bb28
n.z.c.c.g.SerializableTransformer - Serializing resulted in 286 bytes
n.z.c.connect.grizzly.LoggingFilter - Client UDP : Write
---
I interpret this as that the filters are called in the right order. The
next filter in the chain would be the TransportFilter.
However, I don't get anything on the server side. I have a server using
Grizzly code that uses a similar filter chain but nothing happens there.
So to test I used netcat as "server" to see if anything happens (e.g.
netcat -u -l 127.0.0.1 9667) but I get nothing printed there either.
I test using netcat as a client to talk to my grizzly server (e.g. netcat
-u 127.0.0.1 9667) and I see that it tries to handle whatever I send from
netcat so the server seems to at least work to some extent.
If I query the Future I get from udpConnection.write(message) like so:
WriteResult<MessageStruct, SocketAddress> get = write.get();
log.debug("Message {}, dstA {}, size {}", get.getMessage(),
get.getDstAddress(), get.getWrittenSize());
I get:
Message HeapBuffer (746999720) [pos=286 lim=286 cap=286], dstA null, size 0
What am I doing wrong?
Cheers,
Johan