Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a scenario where I am dealing with multiple incoming and outgoing connections. Which design pattern in java will be suitable for me to deal with such scenario.
I have multiple incoming connections like FTP, SFTP , HTTP , Database and multiple outgoing connections also FTP , SFTP , HTTP , Database. I am new to design patterns , I just want to know which design pattern best fit in my case.
I strongly recommend the Half-Sync Half-Async (http://www.cs.wustl.edu/~schmidt/PDF/PLoP-95.pdf) as a general way to deal with the complexity of having (possibly) blocking communication creating asynchronous tasks that need to be executed in order to give a result back to the caller.
It is a very general design pattern so it certainly fits several client-servers protocols you cited.
ESB, suggested in another answer is not adequate to what you are looking for, since it is based on a model in which you have several processes all connected to a message bus. All those processes exchange messages and they are all typically connected to one or more message queues or message topics. Think of it as the postal service. All houses (processes) have the same role and all of them talk with the postal service in order to exchange messages.
In your problem, you have two distinct roles: a client role and a server role. Your problem seems to be how to organize the server internally, not how to coordinate servers or equal peers.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 months ago.
Improve this question
I am implementing a rather simple communicator - one broadcast chat and multiple others for private messaging between users/clients. The purpose of this app is educational and I want to use solutions that are (preferably:)) simple yet modern, flexible, and used in real life, I started implementation using RestController and I stored clients' URLs in the database but I quickly understood that this is not good practice. I want to ask about links and resources that may address the following questions:
How to make a flexible and secure connection between server and client without storing the latter URL?
What is the correct protocol for information exchange in this kind of application
One way to make a flexible and secure connection between a server and its clients without storing their URLs is to use WebSockets. WebSockets is a protocol that allows for full-duplex communication between a server and its clients. This means that the server and the clients can both send and receive messages at the same time, and the connection remains open until it is closed by one of the parties.
Using WebSockets, the server can send messages to specific clients or broadcast messages to all connected clients. This allows for both private messaging and broadcast chat functionality in your application.
You can use a WebSockets library such as Socket.io for Java (https://github.com/socketio/socket.io-client-java). This library makes it easy to set up WebSockets on the server and handle incoming and outgoing messages from clients.
Some resources that may be helpful for learning more about WebSockets and implementing:
The WebSockets API: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
Socket.io: https://socket.io/
A tutorial on using Socket.io for real-time communication: https://socket.io/get-started/chat/
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm given a task to implement Message queue to publish and consume message over queue but my requirement is, i'm gonna need to interact with queue using REST API (eg: ActiveMQ having REST API but problem with ActiveMq is when implementing consumer we don't have way to keep waiting for message queue to fetch,we cant listen to the queue using REST client ).
So i'm leaving my problem to you guys to give me better alternative for this
NOTE - solution should use only open source product only
The issue you are describing is the fundamental difference between messaging (stateful connections) and http-based services (stateless). A stateful consumer can process messages, b/c the broker knows the connection is active. This is also known as a "push" semantic. HTTP-based services are "pull". WebSockets provide a level of "push" available to web-browsers, but in the end you are really just doing STOMP or MQTT over WebSockets.
If you are doing a web application, look to web sockets. If it is a backend application go JMS+Openwire.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have gone through resources on building chat application using socket programming in java. In every implementation people try to make a server which runs in infinite loop, accepting the connections from client and creating a separate thread for handling the chat.
I want to make a chat application in which a new dialog/chat window pops when someone wants to chat with me (on client side). But the catch is that i have only one socket through which i am connected to server. all the messages has to be sent through this streams, currently i am thinking of some adhoc approaches for directing output to different client windows but i am sure that there must be some elegant way to do this.
If you want to use a single socket connection per client, then all communication should be multiplex over that connection, which means that you need to develop a protocol on top of socket streams between your server and a client. A protocol is a set of rules. For example, clients may issue commands and server respond to them, like one command, one response. The commands and responses need to be marked and separated somehow from each other, perhaps you want to add an identifier and a length of a message and then refer to that message.
Various systems use different protocols.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
For example , I develop a connection pool as a server , and on the other application I want to use the connection existing in the pool , How can I get it ? they are in two processes ? and have different life circle ?
If you are talking about socket connections (i.e. your connection pool handles tcp connections), then you can't pass that connection from one process to another. However, you could have a connection from the second process to the server and relay the information to the second process (essentially acting as a proxy).
In general, you will need a way for the two processes to communicate. If they have a different lifecycle (which you hint at) and you need one process to pick up messages from the other process when it comes on line, then you will need a persistence and queuing mechanism as well. Depending on your needs there are many different ways to achieve this. Here are some examples: -
On the server, write the information to a socket and read it on the other process. You would use one of the Java messaging classes and might serialiaze the object information. This is non-persistent, but might be the easiest to begin with.
On the server, write the information to a file and signal either by a named semaphore, file or other means that there is information to be processed.
On the server, write the message to a guaranteed delivery queue (e.g. Amazon or Azure queue) so that it can be picked up by the other process when available.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
My problem is the following, I have two servers from which I have to transfer files, in both directions. The transfer is triggered by a file creation event (on respective sides). The problem is one server has a public IP, the other one doesn't.
I have implemented a socket client that sends a file over a socket, and a socket server which receives and saves it. (Working part)
My questions are : How to keep the socket 'alive' and send some data to the client after a file-system event occured on the server-side ? (Can the server call the client without knowing it's public IP ?)
Can I achieve this with socket technology or should I go for something else like RMI ?
The problem I see is not really an implementation issue. The problem is that you want to keep the client without a fixed address. If you had a fixed IP, I suppose there would be no problem. Right? As you probably understand there is no easy way for a computer to be called without having an address.
An option would be to use an middle solution, wrapping your non-fixed IP with a DNS able to refresh. You could use a service like dyndns to get a domain name which will actually redirect each packet to the real IP. Your router would have to be configured accordingly in order to refresh the IP to the dyndns servers each time it changes.
Another option, would be to use the websockets paradigm which now is part of HTML5. This way, the server would be able to push content to the client whenever he wanted it.
All of the above solutions depend heavily on your detailed scenario and I cannot by anyway guarantee that what I suggest is the best solution. Actually, I would strongly suggest to get a fixed IP which is a lot costless and cleaner solution than the ones I describe.
Hope I helped!