Sending from keyboard/stdin to client-side Socket

"이희승 (Trustin Lee)" trustin at gmail.com
Thu Nov 11 04:23:16 EST 2010


You'd better start from the telnet example, which does what exactly you
want.

mastroGeppetto wrote:
> I am trying to get familiar with Netty, and I wanted to write an Echo service
> client, using a different approach from that found in
> 
> http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/echo/package-summary.html
> 
> My idea is to include the keyboard input loop in the "channelConnected"
> method. Here following is the method:
> 
> public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
> {
> 	System.out.println("Connected with server");
> 	Channel ch = e.getChannel();
> 	BufferedReader stdin = 	
> 		new BufferedReader(
> 				new InputStreamReader(System.in));
> 	String line;
> 	try {
> 		while (( line = stdin.readLine() ) != null && line.length() != 0 ){
> 			ch.write(line);
> 		}
> 	} catch (Exception e1) {
> 		System.err.println("ECHO protocol failure.");
> 		e1.printStackTrace();
> 		System.exit(1);
> 	}
> 	ch.close();
> }
> 
> I obtain the following exception notification:
> 
> java.lang.IllegalArgumentException: unsupported message type: class
> java.lang.String
> 	at
> org.jboss.netty.channel.socket.nio.SocketSendBufferPool.acquire(SocketSendBufferPool.java:59)
> 	at org.jboss.netty.channel.socket.nio.NioWorker.write0(NioWorker.java:461)
> 	....
> 
> Which is probably related to the "ch.write(line)", but I do not understand
> why :-(
> 
> Anybody helps me?
> 
> Thank you!

-- 
Trustin Lee - http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 290 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20101111/7958b573/attachment.bin 


More information about the netty-users mailing list