How do simple message protocols function? [closed] - java

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 am confused how simple message protocols work. I understand the basics of a 3 way handshake checksums, and the like, but from an implementation perspective how do I know if what I am reading is what I should be reading?
When I'm programming a thread to read the input stream of a socket, are there any guarantees? Should each message I send have an ID described from the previous message so I know I am receiving them in order? How can I detect when a message is missed (such as the very last message) so that I am not sitting and waiting for a message that will never come (should I just use simple timeouts)?
Tips on what to search would also be helpful!

TCP sockets guarantee that packets come in the right order. If you look at the headers of a TCP packet, you will notice they have a sequence number. If you are re-implementing TCP over UDP, you will need to provide some of these features yourself.
You should not need to detect if a message has been missed (received 1 and 3 but not 2).
Sockets can be closed unexpectedly though. If a computer goes offline then you aren't going to receive any other packets and there is no time for it to send a warning. Ping/Pong message are often used to make sure both ends are still communicating. Timeouts are your other option.
Are you talking protocols such as TCP (a good low level read)?
Or are you building a chat protocol? XMPP might be a good read for you.

Related

best design pattern for handling multiple incoming and outgoing connections [closed]

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.

how do typical chatting application like yahoo messenger implement chatting with different users? [closed]

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.

What is the most efficient and best way to implement a bidirectional communication system using Java? [closed]

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!

How to read League Of Legends ingame chat in Java? [closed]

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
I would like to read the League Of Legends chat during a match and log it all to a file.
Though I do not have the slightest idea how to actually connect to the server and read the chat.
Does anyone have a link or an idea how to accomplish this?
Regards
You'll have to do some reverse-engineering, since the game's source code is not available. This is likely illegal based on your local laws.
You'll need to use a tool such as Wireshark to figure out how packets are encoded and what is being sent. You'll likely see text strings some of the time, cluing you in to what is happening. By sorting packets and seeing their frequency when doing certain actions, you may be able to deduce what packets must be sent for authentication, keepalive, and chat, and what packets must be listened for.
You can then build a Java implementation using Socket or DatagramSocket for TCP or UDP, respectively, depending on what the original uses. This is quite a bit of work, however, a a major (and did I say possibly illegal?) undertaking. Even with games where the source is available, redeveloping arcane network protocols is difficult and due to lack of information, will require quite a bit of hardwiring (using byte arrays often) for parts of packets.
Just so you're aware, this is probably illegal and I'm fairly certain they'll close your account for this.
The author of this post, Stack Exchange (inc), Stack Overflow, any affiliated parties, or organizations, will not be held liable for any legal consequences you may face. You may choose to do this at your own risk
Edit: You could try to use Robot and simple OCR or text extraction of some sort. It's still a somewhat questionable activity from the standpoint of game administrators and not too reliable.

Better model for my case? RMI or Message System? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I need to build some processes to form a distributed system.
I am in a dillema between RMI and JMS.
Issues:
I opted RMI since I already know it and it fits the distributed systems and it is fast. But the problem is that it is blocking.
I.e. if one of the other process hangs the calling process will be "stuck" on the method call. I think there are some third party libraries but I don't know if they are stable enough.
JMS is a standard and avoids the problem since it is asynchronous. But going this way I have the following issue (also I haven't used JMS before):
If I send a message to one of the processes, I sometimes (depending on the context/flow) need to know that the other process actually did something after receiving my message. But this forms a "synchronous" model, right?
So taking all these into account, what would be the best approach and how my problems would be solved in each case? E.g. my problem with JMS how would it be solved?
JMS is a better solution because of the reasons you mentioned.
Asynchronous
Non Blocking
For receiving acknowledgements you could have the receiver send you messages post some action.
The Actor model which builds on message processing concepts is worth mentioning here.

Categories

Resources