Can netty send more than one response per client request - java

I have a TCP/IP socket server which send multiple response to client based on client's requirement ( like send update whenever DB has an update). client sends xml and server too respond xml.
I stumbled on Netty yesterday. I want to know whether Netty can support my multiple response server application?

Sure as long as the protocol which is used can handle this kind of message flow.

Related

REST Server to client communication

I'm developing a Java API for an Adndroid app in Spring. Right now my API is 100% REST and stateless. For the client to receive data, it must send a request first.
However, what I need is the server to send data to the to the client /not the client to the server fisrt/ whenever it is ready with it's task.
I think that some kind of session must be created between the two parties.
My question is: How can I achieve this functionality of the SERVER sending data to the CLIENT when it's ready with it's task? /It is unknown how long the task will take./
What kind of API should I develop for this purpose?
One idiotic workaround is sending a request to the server every n seconds but I'm seeking for a more intelligent approach.
There are multiple options available. You can choose what suits best for you.
Http Long Polling - In this, server holds the request until it's ready with its task (in your case). Here, you don't have to make multiple requests every few seconds (Which is Http Polling).
Server Sent Events - In this, server sends update to the client without long-polling. It is a standardized part of HTML 5 - https://www.w3.org/TR/eventsource/
Websockets - Well, websockets work in duplex mode and in this a persistent TCP connection is established. Once TCP connection is established, both server and client sends data to and fro. Supported by most modern browsers. You can check for Android Websocket Library like autobahn and Java websocket.
SockJs - I would recommend to go with this option instead of plain WebSocket. http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#websocket-fallback-sockjs-enable

Check if client is online

So I have a server with a few clients.
When a client sends in a message I'd like the server to send it out to any one of the clients. However I don't really want the clients to be polling for messages, rather, I'd somehow like the server to check if they are online and then send them the message if they are.
I'm assuming the client will need a socket that's listening for incoming messages?
But what's a good method for the server to 'test' if the client is online? How the server know the address of the client?
I'm using Java with JAX-WS.
I'm sure there must be some method or design pattern for this that I'm not finding via google?

Sending SOAP http response in one package

We have a Java web service with document style and http protocol. Local this service works smoothly and fast (~ 6ms). But calling the service-methods from remote takes over 200ms.
One main reason for this delay is that the
server sends first the response http header,
the client sends in return a ACK and
then again the server sends the response http body.
This second step where the client sends the ACK costs the most time, almost the whole 200ms. I would like to avoid this step and save the time.
So that's why my question: Is it possible to send the whole response in one package? And how and where do I configure that?
Thanks for any advice.
I'm not fully understanding the question.
Why is the server sending the first message? Shouldn't the client be requesting for a web service via HTTP initially?
From what I understand, SOAP requests are wrapped within an http message. HTTP messages assumes a TCP connection and requires a response. This suggests that a client must respond when the server sends an http header.
Basically whatever one end sends to another, the other end must reply. The ACK return from you step 2 will always be present.
EDIT:
I think the reason for the difference in time when requesting via local and remote is simply the routing that happens in the real network versus on your local machine. It's not the number of steps taken in your SOAP request and response.

Implementing a protocol exchanging four messages within a single persistent connection

I have a complete implementation of a protocol where four messages are exchanged between the client (a native Android application) and the server (a standalone Java server) in the following way using a persistent connection through Java sockets:
(client->server): message1
(server->client); message2
(client->server): message3
(server->client): message4
Between sending each message, both client and server have to do heavy mathematical (cryptographic) operations (pairing-based computations over elliptic curves).
This project works properly in my local development machine using sockets and mantaining opened this socket from message1 to the message4 between the Android app and the Java server. Now, I need to do the same with Google AppEngine, but since it does not allow opening sockets, I do not know how can I do it. I already checked the Channel and XMPP APIs, but I do not know whether my use-case applies to that APIs. Is it the right method using Channel and XMPP APIs from AppEngine? Is it possible to emulate the functionality implemented in my local machine through sockets on AppEngine?
Thank you for your response.
Google App Engine doesn't support persistent connections.
You will need to significantly re-design your protocol to run over HTTP.
As an example, message1 can be sent over an HTTP request, message2 can be returned with the matching HTTP response. At that point, your socket connection ends.
You'll have to issue a second HTTP request to open a new socket with message3, and you can return message4 with the second HTTP response.
You can "connect" the first and second HTTP request by using an HTTP session. A session is basically an id with extra data stored on the server side. You'd create the session in the first HTTP request, and pass it as a parameter to the second HTTP request. The server can look up the session id and the associated data when processing the second request.
You can find more info about sessions on SO: How to use session on Google app engine
The XMPP API will not help you, it's for communicating between the GAE server-side code and other XMPP clients that use HTTP as a communcation protocol.
The Channel API can be used to send data from the server->client, but it's actually implemented as an HTTP long poll. Multiple long HTTP requests are used, and you are not guaranteed to have a single socket that stays open; multiple sockets are opened and closed in the process. It will be more complicated that what I described above, and more expensive.

Communication between two clients of web application

Let's say I want to send a message from one client to another. How should I approach this problem? Obviously I will have to send this message to server, but what's next? I have few ideas, but every idea seems to be wrong.
thanks
Client1 - send message for client2 to server
Client2 - check any period of time for the messages
OR
Client2 - Open Websocket to the server.
Client1 - send message for client2 to server
Server - push message to client2
direct client-to-client communication my be very difficult due to client firewalls.
Look at the tutorial for sockets in java
http://docs.oracle.com/javase/tutorial/networking/sockets/
Also you don't necessarily need a server. You can have the clients have both an incoming and outgoing channel and do it that way.
So
Client1 sends on its outgoing to Client2's incoming
Client2 hears on its incoming and responds on its outgoing to Client1's incoming
Client1 hears on its incoming
You can use the standard Java JMS approach to send asynchronous messages between applications. Read more at : http://java.sun.com/developer/technicalArticles/Ecommerce/jms/
If by web application you mean HTTP based, than you must know HTTP is a request based protocol. In other words, the server only responds to HTTP requests that come from the clients (browsers, most of the time), so after a client sends a message, all the other clients that want to receive that message must ask for it, i.e. make a request to the server. Typically, this is achieved using an auto-refreshed HTML page.

Categories