Answer the question
In order to leave comments, you need to log in
JAVA - how to organize a protocol for communicating between a client and a server?
Hello and thanks a lot for your replies.
I would like to ask in what way it is customary in java to "resolve" incoming packets from the client on the server, serialization and deserialization of packets from json or protobuf, as an option for the data format, this is more or less clear, but in what way (I think there are quite a few) is best "resolve" incoming data into class methods?
So far, 2 possible options come to mind:
1) Send the command identifier in packets and then call this or that method through switch.
2) I suspect there are implementations for calling by method name:
php:
- function_exists to determine if a method
exists - call_user_func for
lua calls:
- pcall to call
Perhaps I described something incorrectly, thanks for understanding.
Answer the question
In order to leave comments, you need to log in
Pay attention to this resteasy.jboss.org
framework
Working with it is quite simple and will solve most of your needs. Here is the simplest example www.mkyong.com/webservices/jax-rs/resteasy-hello-w... We do this - there is a shared project containing DTO classes. Both the client and the server know these classes. The client sends a request to the server. DTOs are wrapped in JSON RestyGWT (we write in GWT). The server parses with RestEasy. Also here is a good library for working with JSON https://code.google.com/p/google-gson/ , it may come in handy.
If the data is binary, then you can use protobuf for (de)serialization, for calling functions - I recommend either simple REST on servalets or JAX-RS.
Here's what I found quickly
- sleeplessinslc.blogspot.ru/2010/03/restful-represe...
- www.javarants.com/2008/12/27/using-jax-rs-with-pro...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question