Le 18/02/15 01:19, Abeer Al-Anazi a écrit :
> I want to send data periodically from client to server. How can I do that
> in Mina while the data well send via client handler.
> I write openSocket() function like this:
> public void openSocket(Object c)
> {
> connector.getSessionConfig().
> setReadBufferSize(2048);
> connector.getFilterChain().addLast("logger", new LoggingFilter());
> connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new
> myCodecFactory()));
>
> connector.setHandler(new
> net.floodlightcontroller.Example.ClientSessionHandler(c));
> ConnectFuture future = connector.connect(new
> InetSocketAddress(HOSTNAME, PORT));
> future.awaitUninterruptibly();
>
> IoSession session = future.getSession();
> session.getConfig().setUseReadOperation(true);
> session.getCloseFuture().awaitUninterruptibly();
>
> connector.dispose();
> }
> as you see the function receive an object which contain my initial data
> after I call it in init() function. if I want to send another data after a
> period of second by the same connection, How can I do that. if I call
> openSocket() function like below code it does not work. where can I call it
> and How?
> try {
> while (true){
> openSocket(cObj);
> Thread.sleep(5000, 5);}
> } catch(InterruptedException ie) {}
>
Once you have opened the socket, why do you want to open it again ? Also
in your openSocket method, you do a
session.getCloseFuture().awaitUninterruptibly() which is totally useless.
Your description is also inconsistent. You say that you want to *send*
data from the client to the server, but later on you write that the
function *receives* an object. Adn, no, we don't 'see' that the function
receive something, because we don't have the handler code.
Just do that :
- create a connector
- using the connector, get a session
- use this session to send the server what you want, without closing the
connector
- when you ard done, you can close the session and dispose the connector.
Keep in mind that establishing the session is the most expensive
operation, sending data is just a breeze compared to that.
Hope it helps.