data sending server to different client data - java

I am doing a project of Restaurant ordering system in that I gave order by using different client and process that order and that order can send different system, e.g:
kitchen1
Kitechn2, and
kitchen3
First I can create different client by using rmi threading concept an and they can send (means all client) data to my server i want to sent that data into different client
How can I do that? I do create different client and send data to the server suggest how can I do that?

RMI is a synchronous (request/response) protocol - the client sends a request to the server, which it can respond to.
The server cannot arbitrarily send more data to the client.
The simplest way to asynchronous communication in Java via JMS using a message broker like Active MQ.
The process would go something like this:
the server starts and connects to its incoming request queue.
client 1 creates a temporary queue and registers with the server via the request queue passing the name of its temporary queue.
the server stores the client and the name of its termporary queue.
client 2 does the same and server stores the client and the name of its termporary queue.
client 1 sends a message to the server causing the server to send a message to client 2, which is does via the temporary queue that client 2 registered with the server.
client 2 reponds to the server causing the server to send a message to client 1, which is does via the temporary queue that client 1 registered with the server.
This can go on until one or both client shuts down, at which point their temporary queue are closed and the server can no longer send messages to that client (though it's best the client de-registers itself).

Related

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?

Server/Client application do not communicate in all executions but only in some (Code unchanged)

I have implemented a client and server. Both implement quickfix.Application and use ThreadedSocketInitiator/ThreadedSocketAcceptor to initiate/accept sessions. The client starts a thread that sends messages to the server. The call back function fromApp of the server, sends the response to client. Server is receiving requests from the client and responding to them, but the client is not receiving the responses. Note that this does not happen all the time. 2 out of 10 times, the same code works perfectly as expected and both client and server communicate. I do not understand what is going wrong.

Connect Server to multiple clients

I have created a client/server application. Now, clients can send requests to the server and receive server response. Now I want to notify all connected clients to perform some actions. How can I do that?
Register all connected clients on the server and store references to clients in the List instance.
If you want to inform your clients asynchronously then open ServerSocket instance on your every client and accept connections only from the server they are using.
And in this case your server acts as a client and sends a request to all connected clients like a client sends request to the server.

Constant data feed from a log file to wan

I am looking for an efficient way to feed a log file via the network (a demon of sorts). Each packet being a number of lines from the log file so that they can be processed from the other end. It is important for the server to be independent from the client meaning that it should be able to 'hold' the packets to be sent when the client is connected.
Note : I am aiming for a two-way communication, not a broadcast.
You could try using message queue middleware e.g. RabbitMQ. Its a nice way to decouple two systems like you describe. The message broker (RabbitMQ) will queue messages until the client/server connects and consumes them. You can have one queue for messages for the server and another queue for responses destined for the client. You could run RabbitMQ broker only on the server or you can have one on the client as well and shovel messages between them.

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