FAQ Database Discussion Community


Run multiple servers in Netty without closeFuture().sync()

java,netty
I'm working on a Netty application. I want to run multiple servers on different ports and that is not working without the (blocking) closeFuture().sync(). I start the servers in my ServerManager class using the following code: gpcmServer = new GpcmServer(port); gpspServer = new GpspServer(port); In those classes, I start the...

how to ask different questions with TestWebSocketFrame in netty

java,netty
I am using for writing to a socket. channels.writeAndFlush(new TextWebSocketFrame(String msg)); and in my webpage (that is displayed to the client) I obtain the data from the event(event.data) and display it in the text area(say T1). but i have 2 text area's (say T1 and T2) and I want to...

Basic Netty Demo cannot handle TCP and UDP sockets at once

java,tcp,udp,server,netty
I have the following files: https://gist.github.com/anonymous/58c7cf4341acfe83f279 I am aware I can greatly simplify this, I am simply doing this for conceptual reasons. When I run this, only the UDP connection works. When I comment out the UDP, the TCP works fine. Why are both sockets not working at the same...

Netty 4, use the current thread for an HTTP client

netty
I would like to write an HTTP client, using Netty 4, that does not requires the creation of any additional thread. I started working from the HttpSnoopClient and tried replacing: EventLoopGroup group = new NioEventLoopGroup(); with: EventLoopGroup group = new NioEventLoopGroup(1, new Executor() { public void execute(Runnable command) { command.run();...

Netty - Client/Server chat

java,client-server,netty
I need to have a client/server communication in netty for one of my project purpose. So I just started with a handsOn to improve from that.I am learning netty and I am a beginner in that. I have tried a simple client server chatting with netty. The client and server...

How to interpret this Java generic type definition?

java,netty
Below is some code snippet from the netty 4.0.24 framework. It's kind of confusing to interpret the B type parameter. public abstract class AbstractBootstrap<B extends AbstractBootstrap<B, C>, C extends Channel> implements Cloneable { ... } ...

NettyIO disconnect Client from Server

java,connection,handler,netty,channel
How can I disconnect a netty client from the server so it executes the handerRemoved method on the server side and completely stops running? I tried using group.shutDownGraceFully() but the client still keeps connected to the server. Is there any method I am missing? I also noticed when I try...

when netty connects to my server?

java,netty
I am using the Channle pool API code written here: ChannelPool section http://netty.io/news/2015/05/07/4-0-28-Final.html EventLoopGroup group = new NioEventLoopGroup(); final Bootstrap cb = new Bootstrap(); InetSocketAddress addr1 = new InetSocketAddress("10.0.0.10", 8888); InetSocketAddress addr2 = new InetSocketAddress("10.0.0.11", 8888); cb.group(group).channel(NioSocketChannel.class); ChannelPoolMap<InetSocketAddress, SimpleChannelPool> poolMap = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() { @Override...

udp socket receive buffer size

java,sockets,networking,netty
I am use Netty ( a java network framework) to server UDP request . I found the SO_RCVBUF and /proc/sys/net/core/rmem_default and /proc/net/udp output confusing: By the manual of socket( man 7 socket) It explains : rmem_default contains the default setting in bytes of the socket receive buffer. rmem_max contains the...

Netty: Bound Mismatch

java,abstract-class,netty,nio
I am new to java and was trying to use Netty to build a sample tcp server. Here is what i have currently package http_server; import java.net.InetSocketAddress; import java.nio.channels.SocketChannel; import netty_tutorial.EchoServerHandler; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInitializer; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;...

Deserialize an Object with Camel-Netty4

sockets,apache-camel,deserialization,netty,decoder
At the client side I have a working-fine socket sending a Java Object: Detail detail = new Detail(); //client object Socket client = new Socket(host, port); OutputStream out = client.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(detail); oos.flush(); Note: this is the client socket so cannot be changed. At the server...

Continue pipeline after WebSocketServerProtocolHandler when no upgrade specified?

websocket,netty
I have WebSocketServerProtocolHandler handler on the root path, where I also accept regular HTTP requests. However, WebSocketServerProtocolHandler wont let me use my HTTP request, as it assumes everything is web sockets and responds with: not a WebSocket handshake request: missing upgrade Can I simply continue execution of the pipeline after...

difference between p2p and client-server node design

client-server,netty,p2p
I have some time of experience in server-client application development with c++ native call (epoll,etc), now i am trying to do something with p2p with netty. But I couldn't make clear different between p2p and server-client design. IMHO, p2p is just like a server application but also will make connection...

How to create channel pool in netty?

java,netty
I am creating channel using this sample code: EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group) .channel(NioSocketChannel.class) .option(ChannelOption.SO_KEEPALIVE, true) .handler(new ClientInitializer()); // Start the connection attempt. Channel ch = b.connect(host, port).sync().channel(); So here my getting a channel(channel future) but my application throughput will be very...

Netty: Using a channel defined in the anymous inner class within another method

java,connection,netty,channel,anonymous-inner-class
I have implemented a server-client connection in Netty, I can send and receive data between the two connections. public void start() { // Start the interface bossGroup = new NioEventLoopGroup(); workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void...

Is it OK to use HashedWheelTimer for long running and periodic tasks?

timer,scheduled-tasks,netty
Currently I am using the Netty timer for long running tasks (database access) and periodic tasks (simply creating new timeout on execution). But now I am getting unsure if this is alright.

Reference Count Object

java,netty,nio
In netty, Objects processed by ChannelHandler(s) should be released by calling ReferenceCountUtil.release(). I am using customized objects in my application and documents says any object needed to be released should implement ReferenceCounted so it could be managed by netty framework. So should we put a clean up handler at the...

Add channel handler for gzip deflate in netty proxy

java,netty,little-proxy
In the following file: https://github.com/adamfisk/LittleProxy/blob/master/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java I need to add a 'channel handler' which will deflate gzipped content. I have no idea how to do this having no netty knowledge. Can somebody give me a point in the right direction?...

Wildfly - “Connector 'netty' not found on the main configuration file”

java,eclipse,jboss,netty,wildfly
I've added a connection factory at the standalone-full file of Wildfly: <jms-connection-factories> <connection-factory name="K19Factory"> <connectors> <connector-ref connector-name="netty"/> </connectors> <entries> <entry name="K19Factory"/> <entry name="java:jboss/exported/jms/K19Factory"/> </entries> </connection-factory> ... </jms-connection-factories> And I have the following code to use it: Properties props = new Properties();...

“Not on FX application thread” exception with Netty and JavaFX

java,javafx,netty
I am creating a Netty/JavaFX application and i faced with a following exception when i try to send a picture from client to server. Exception in thread "nioEventLoopGroup-3-1" java.lang.IllegalStateException: Not on FX application thread; currentThread = nioEventLoopGroup-3-1 at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:204) at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:364) at javafx.scene.Scene.addToDirtyList(Scene.java:485) at javafx.scene.Node.addToSceneDirtyList(Node.java:424) at...

Netty doc bug for ServerBootstrap.group()?

netty
The netty javadoc for ServerBootstrap.group() method is this: I think the SocketChannel should be ServerChannel. I am using Netty 4.0.24.Final....

Netty NioSocketChannel got broken message on multithread write

java,multithreading,netty,nio,messagepack
I'm writing my own simple game server using Netty 4.0.25. I want to support msgpack binary data so every message send/receive on a channel always encoded/decoded by msgpack. my server: bossGroup = new NioEventLoopGroup(4); workerGroup = new NioEventLoopGroup(4); bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup); bootstrap.channel(NioServerSocketChannel.class); bootstrap.handler(new LoggingHandler(LogLevel.DEBUG)); bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {...

How to discard/release message in MessageToMessageDecoder in Netty 4

java,netty
What should I do if inside my decode method i want to discard the message (for instance if this type of message is not supported by this client)? In other words I don't want to pass decoded message to another (business) handler. To avoid memory leak and be consistent with...

Setting system property application.secret for Play and initialization order

scala,playframework,netty
I'm using NettyServerComponents to embed Play in my application server and I'm having problems with setting the required "application.secret" programatically. The call I make is: System.setProperty("application.secret", secret) and I can verify that it is set via System.getProperty("application.secret"). However initialization will fail if I put the call inside the class that...

NettyIO not correctly removing channels

java,error-handling,handler,netty,channel
I have a problem: Netty is not correctly removing the channel which disconnected in the handlerRemoved method. When I reconnect the client to the server, I get the following error: io.netty.channel.ChannelPipelineException: com.test.netty.NettyServerHandler is not a @Sharable handler, so can't be added or removed multiple times. at io.netty.channel.DefaultChannelPipeline.checkMultiplicity(DefaultChannelPipeline.java:464) at io.netty.channel.DefaultChannelPipeline.addLast0(DefaultChannelPipeline.java:136) at...

Stubbing SOAP requests in Scala

scala,soap,netty,scalaxb,betamax
I use scalaxb to generate models and client part of the SOAP interface. For testing I use Betamax, which can also be used in Scala. However, scalaxb uses Netty as a transport, which ignores proxy settings set up by Betamax. How would you cope with this situation? scalaxb uses cake...

Do associated futures complete on closing of channel?

java,asynchronous,network-programming,netty,future
If I create a future by Channels.future(Channel), is it automatically completed (to failure?) when the channel is closed? (Netty 3.10.0)

Advantage of ChannelInitializer over Channel Handler in Netty

java,netty,nio,channel
What are the advantages of using ChannelInitializer over a chain of ChannelHandlers directly? For example with a server bootstrap I could do: bootstrap.childHandler(channel_handler); Add in the implementation of channel_handler i would implement the following class simple_channel_handler implements ChannelHandler { public void handlerAdded(ChannelHandlerContext ctx) throws Exception { // TODO Auto-generated method...

How to Share content between Handlers on Netty?

java,netty
I'm developing a game server and decided to go with Netty as the server framework. The idea is that Server will receive status and actions from clients (TCP) and forward back to him and to all others, what these actions resulted. 1) How to store the shared content of the...

How to import a maven project from SVN tags into eclipse?

eclipse,maven,svn,netty
(This may be a dumb question but I am not quite familiar with the interesting eclipse importing logic) I am trying to read the source code of Netty, so I checkout the tag folder for Netty-4.0.24.Final from the Netty SVN (https://github.com/netty/netty). The files are shown as below: Since there's a...

Should I use DefaultEventExecutorGroup or custom Java Executor?

java,multithreading,netty
I don't want to block UI (golden rule :). Should I: A) create DefaultEventExecutorGroup and use it when I add my ChannelHandler to the pipeline: pipeline.addLast(eventExecutorGroup, "foo", fooChannelHandler); B) or use my custom java thread pool inside my ChannelHandler instance and then fire a task in my messageReceived method? Using...

Netty TCP push/streaming server

java,tcp,netty
Is it possible to implement request for stream style client server interactions at the tcp level in netty? The protocol would essentially follow: t0: tcp handshake t1: client requests topic X t2-tn: server sends latest enqueued update on topic X I've seen a netty websockets example, but is it possible,...

Is this ChannelFuture listener registration robust?

java,networking,netty,nio
Below is some code snippet from the book < Netty in Action >. I am wondering if the connect action finished after 1 and before 2, will the ChannelFutureListener ever get a chance to be notified?...

Need to reassemble tcp packets with netty

java,sockets,tcp,netty
currently I am working with an inhouse protocol where I send a request to our hardware and receive the answer with netty. In the message which I receive are several bytes which tell me how many bytes the answer will contain. In my channelRead method I wait until the readable...

java.io.StreamCorruptedException: invalid stream header: 48656C6C

java,bytearray,netty,objectinputstream
I am using netty client server for communication . The message is received successfully as byte array . When I convert byte array to ObjectInputStream I get the exception java.io.StreamCorruptedException: invalid stream header: 48656C6C at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) at nettyClientServer2.PongHandler.messageReceived(PongHandler.java:99) at...

iOS protobuf GCDAsyncSocket

ios,netty,protocol-buffers,gcdasyncsocket,cocoaasyncsocket
I am writing a small app which requires sending protobuf message to a netty server via tcp, where CocoaAsyncSocket/GCDAsyncSocket is used. To do this, I use the following code: Message_LoginMessageRequest_Builder *msg_tmp_login_build=[Message_LoginMessageRequest builder]; [msg_tmp_login_build setPhoneNumber:input_phone.text]; [msg_tmp_login_build setEmail:input_email.text]; [msg_tmp_login_build setPassword:input_password.text]; Message_Builder *msg_tmp_build=[Message builder]; [msg_tmp_build setType:Message_MessageTypeLoginReq];...

JMeter test on Netty-based impl produces error for every second request

java,jmeter,netty
I've implemented an HTTP service based on the HTTP server example as provided by the netty.io project. When I execute a GET request on the service URL from command-line (wget) or from a browser, I receive a result as expected. When I perform a load test using ApacheBench (ab -n...

How to close AsyncHttpClient with Netty for an asynchronous Http request?

java,asynchronous,netty,asynchttpclient,completable-future
Using the AsyncHttpClient with Netty provider will prevent the main program to terminate when we execute an asynchronous request. For instance, the following program terminates after the println, or not, depending on whether the provider is JDKAsyncHttpProvider or NettyAsyncHttpProvider: public class Program { public static CompletableFuture<Response> getDataAsync(String uri) { final...

Java Packet Handler Threading

java,multithreading,sockets,netty
I have a quick general question. I am currently using Netty to handle TCP and UDP packets coming from a client. I have the socket listeners each on a separate thread and it works great. My concern now is, when traffic starts hitting it heavily, I don't think a single...

Camel netty component example doesn't work, within Spring MVC

spring,apache-camel,netty
I've tried out a good looking example in this topic ( http://shengwangi.blogspot.hu/2015/01/camel-netty-hello-world-simple-example.html ), but it doesn't work for me. I would like to create an simple workable TCP adapter, which uses an own encoder and decoder. At first I check out above example ( it uses a simple String encoder...

Netty IO check if Server closed

java,client,handler,netty,server
how can I check if the Server closed/shut down on the client-side? I want to notice the user when the Server closed. Is there any method to do that?

Netty: Is ChannelFuture/ChannelFutureListener guaranteed to be “per-message”?

java,netty
I have a channel which needs to stay open because a lot of messages get written and I don't want to do a SSL-Handshake for every write. If I would do this: ChannelFuture future = channel.writeAndFlush(message1); channel.writeAndFlush(message2); future.addListener(new ChannelFutureListener(){ @Override public void operationComplete(ChannelFuture channelFuture) throws Exception{ //check for success }...

Are channelActive and channelRead guaranteed to be invoked by same thread for specific channel?

netty
I'm using netty 4.X Netty in action book mentions that "All of your ChannelHandlers, which contain your business logic, are guaranteed to be executed by the same Thread for a specific Channel." I wanted to confirm that channelActive and channelRead guaranteed to be invoked by same thread for specific channel....

Different Netty versions and their purposes

java,netty
I am using Netty for a while now and could never solve this question. One can download four different versions. Three of them are actively getting developed. 3.x 4.0.x 4.1.x 5.x As far as I understand 3.x is for JRE 1.5 and everything else for JREs greater than that. I...

is there transferFrom like functionality in Netty for zero copy?

java,http,netty,nio,zero-copy
I'm developing a Http server that processes fairly large size of payloads. Since Netty provide zero-copy, I thought of using zero-coping of the payload using Netty's zero-copy. But it seems Netty only provide transferTo(WritableByteChannel target, long position) but not providing transferFrom() like method to read the content directly in to...

Netty: Weird IndexOutOfBoundsException: readerIndex + length exceeds writerIndex

netty,indexoutofboundsexception
I am currently sending different packets through netty and I'm very often getting exceptions like these when receiving them: java.lang.IndexOutOfBoundsException: readerIndex(39) + length(32) exceeds writerIndex(64): UnpooledUnsafeDirectByteBuf(ridx: 39, widx: 64, cap: 2048) at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1166) at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:655) at <snip>.PacketDataHolder.readString(PacketDataHolder.java:79) ...... or...

Netty bootstrap with boss group or with just with workers EventLoopGroup

netty
The book and examples indicates that we should use the so-called boss group and the worker group when bootstraping the server: serverBootstrap.group(bossGroup, workerGroup); And then, in the Vert.x that is based on Netty we have: bootstrap.group(availableWorkers); which mean (afaiu) that all workers is going to work the same, so no...

How does netty determine when a read is complete?

java,networking,netty,nio
Below is a ChannelHandler for a echo server. Netty framework will call channelReadComplete() method to notify the handler that the last call made to channelRead() was the last message in the current batch. My question is, since data are transferred on wire in trunks, how could Netty know when a...

How to get notified when unfiltered Netty server actually gets shutdown?

scala,testing,netty,unfiltered
I have an Unfiltered Netty server that I need to shutdown and restart after every test. val mockService = unfiltered.netty.Server.http(mockServicePort).handler(mockServicePlan) before { proxyServer.start() } after { proxyServer.stop() } Currently, this is not working, and I am fairly certain that is because the stop() function is non-blocking and so the following...

Netty / Shiro Integration

http,netty,shiro
Instead of writing my own authentication handler, I'd like to use an existing authentication framework, e.g. Apache Shiro. After some research I have found that integrating Shiro with netty is not a straight forward task, although passing the Subject along the channel is not a problem, but rather setting up...