N
N
Nube2017-01-30 14:51:08
Java
Nube, 2017-01-30 14:51:08

How to transfer data over the network?

Hello. I have a simple server and client, both in java. I was able to successfully transfer a String from the client to the server, now I want to transfer an object, for example Account, where there are password(char) and email(char) fields. I would like to know how to transfer it, in the form of json format or should I send an array of class fields Account, and how is it done in WhatsApp or VKontakte? Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Cheremisin, 2017-01-30
@Nube

1) It is bad to transfer an array of fields. Imagine that in 5-10 days you need to add one more field. You will have to change the code on both the client and the server.
From this conclusion - data packaging should, if possible, be variable to the data so that adding a new class field does not kill everything in the bud. A hundred or two protocols are suitable for this, starting from json (which is very good), and ending with protobuf (which is also very good), you can even pack in XML, everything here depends on taste and color. I prefer json.
2) It is better to do the exchange on standard high-level protocols, starting from HTTP (S) and ending with some kind of XMPP, you can use message queues like RabbitMQ / ZeroMQ and the like. My favorite is HTTP.
Accordingly, on the one hand, there must be an HTTP server or an application that emulates it, or a servlet. On the other hand, a client that sends requests to your server. Well, drive the data through json.

V
Vit, 2017-01-30
@fornit1917

Pass it on as you wish. If both the client and the server are in Java, then you can at least do standard serialization ( www.java2s.com/Code/Java/Network-Protocol/ObjectIn...

A
alex maslakoff, 2017-01-30
@teke_teke

Yes, in json. It is possible in xml'e.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question