ari-ban / issue-test

0 stars 0 forks source link

can anybody provide a example for grizzly server and a normal client? #1998

Closed arinban closed 6 years ago

arinban commented 6 years ago

can anybody provide a example for grizzly server and a nomral client,when i use a normal socket client to visit the grizzly server,it refused.

arinban commented 6 years ago
arinban commented 6 years ago

@carryel Commented Maybe I think you can refer https://github.com/javaee/grizzly/tree/master/samples. And if you can afford to review another projects, you can see https://github.com/javaee/grizzly-thrift and https://github.com/javaee/grizzly-memcached which have custom server and client(XXXFilter.java).

arinban commented 6 years ago

@sawshaw Commented i have see the example,but i just feel uncertain that when use netty server,i can use https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/netty/ThreadTest.java to visit the nettyServer https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/netty/NettyServer.java,but use that i can't visit Grizzly server https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/grizzly/GrizzlyEchoServer.java the question is why i use the same client can't visit different socket server?

arinban commented 6 years ago

@carryel Commented When I reviewed your code, this issue caused from StringFilter's StringDecoder/StringEncoder.

https://github.com/javaee/grizzly/blob/master/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StringDecoder.java (https://github.com/javaee/grizzly/blob/master/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StringEncoder.java)

StringDecoder expects a terminating symbol or fixed length's string(length + data) but the client sends pure string.

If you should StringFilter, the simplest solution is that adding the terminating symbol:

https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/grizzly/GrizzlyEchoServer.java#L30

filterChainBuilder.add(new StringFilter(Charset.forName("GBK"), "\r\n"));

https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/netty/ThreadTest.java#L16

String f="00000000111111100000000\r\n";

Another solution is that the client should use grizzly's StringEncoder.

arinban commented 6 years ago

@sawshaw Commented it seems worked ,thank you very much. by the way, if there have any solution that don't alter client to let's the server worked?i have see mina,grizzly,netty framwork.mina and grizzly also need a terminating symbol,and it's should alter the client,when i use netty, the string's length byound 1024 ,i have to alter aclient to suit it,the original nio has some bugs and i can't deal with it gently.

arinban commented 6 years ago

@sawshaw Commented thanks again, i have solve above problem use mina, the example llike this https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/mina/MinaServer1.java and https://github.com/sawshaw/java-network-programming/blob/master/networkProgramming/src/framework/mina/MinaServerHandler1.java