Answer the question
In order to leave comments, you need to log in
Java chat (JavaFX client interface), how to do?
I am doing a chat, with registration and authorization (I have no experience in Java).
Question one: What is the best way to send an object from the client to the server? Don't be too smart. I wanted to first convert the object to xml , then convert it to a string and send it to the server, and on the server already "pull out" the object from xml . Everything seemed to be going well, the line came to the server, I could even output it somewhere, but it doesn’t want to be converted into an object, although it’s xml code (I climbed everywhere, but nothing helps, if necessary, I’ll throw an example when, like me do). If I'm still not doing it right, then tell me how to do it better. Which serialization is better to use and how to send the serialized object to the server.
Question two: I have not yet decided how exactly I will do it, or a general chat, or so that clients can chat with each other, or even create groups (rooms). But the question is different, Here is the Login and Password will be stored in the database. But I would also like to make sure that there is a history of messages, and not just a chat every time from scratch for each client. So here's the question: How to save correspondence in general, in a database or somehow else, for example, in files, maybe some on the server itself (This is my guess).
If it's not difficult, then help me, I'm doing the chat purely for myself, and let me remind you that I've been doing Java recently. A simple chat has already been made and parsed, which worked as an echo server, when one user sent a message and this message was sent to other users.
PS I do on sockets.
Answer the question
In order to leave comments, you need to log in
This is the second question you've asked, and it's still stupid.
First of all, what does javafx have to do with it? This is generally ui and no side, and even more complexities, simply by definition, there can be no way at all and no side.
Secondly, absolutely, I emphasize ABSOLUTELY, all that should worry at the moment is architecture. And you NEED to start with it, sit down, just take a piece of paper and write in paragraphs in a column what you need from the chat, that’s all you want from it, draw a line and group the Wishlist on the right in a column according to their meaning, then for the received groups on the right write pseudocode what will be used for this feature and what data types will go. I already cited something like this in your previous question, but I’ll throw in an example here as well.
Thirdly, you need to come to the toaster with a specific problem, and even with which it was not possible to google anything, something like here I have serialization, here is the serialization method, here is the deserialization, but here is an error and I can’t understand why.
For the second point, an example
I want | Association of similar | How to do
------------------------------------------------ -------------------------------------------------- -------------
1 chat with a friend | 1 | Format (to whom, from whom, message)
2 story | 2 | Store in sql db message format
3 chat with everyone | 1 | Format (from whom, message)
4 chat with everyone but in the room | 1 | Format (from whom, room, message)
5 authorization | 3 | store in sql database, transfer Format(login, password)
6 communication client server | | Text view, Json
7 registration | 3 | store in sql , pass in Format(login, password)
n
According to the result, you take and systematize more specifically like this:
1) Many different message formats have been drawn and it is necessary to distinguish them somehow, which means I will make a parent class with an int field that will store the message type. The problem of information exchange between the client and the server is completely solved on both sides.
abstract class AMessage{
int messType;
}
public <T> T fromJson(String json, Class<T> classOfT){
Gson gson = new GsonBuilder().create();
try{
return gson.fromJson(json, classOfT);
}catch(JsonSyntaxException jse){
return null;
}
}
public String toJson(Object obj){
Gson gson = new GsonBuilder().setPrettyPrinting().create();
try{
return gson.toJson(obj);
}catch(JsonSyntaxException jse){
return null;
}
}
//от кого, комната, сообщение
class RoomMessage extends AMessage{
String from;
String roomName;
String message;
RoomMessage(String from, String roomName, String message){
this.messType = 10;
this.from = from;
this.roomName = roomName;
this.message = message;
}
}
What is the best way to send an object from the client to the server?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question