javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
222 stars 60 forks source link

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

Closed sawshaw closed 6 years ago

sawshaw 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.

carryel commented 6 years ago

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).

sawshaw commented 6 years ago

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?

carryel commented 6 years ago

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.

sawshaw commented 6 years ago

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.

sawshaw commented 6 years ago

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

glassfishrobot commented 6 years ago

Closing this as this issue is migrated to https://github.com/eclipse-ee4j/grizzly/issues/1998