Home > Back-end >  QT TCP communications how to implement one-on-one private chat?
QT TCP communications how to implement one-on-one private chat?

Time:09-21

Such as topic, now I know that is after the server receives the data if for all online news forwarding data to the client and then determine whether to send their data if it is to display a message, but their tried, the result is not ideal, solving ~ ~ ~

CodePudding user response:

It is best to give a small example for bosses like ~ ~ ~

CodePudding user response:

Need not mass, the server hold above all user's information, user ID as the index, can quickly locate the user information,
User information, including online state, whenever the cli to connect to the sever, cli active report a message [online], contains its own cliID,
User is offline, then there are two ways to realize the connection status updates, like online, cli reported an offline command (bring your own id, message format design],
If the server is disconnected, this time by connecting to, you are looking for a user id, your consideration, have the necessary to design the data structure,
(server active disconnect a client scenario is what? , such as a connection how long no news between us, whether its force disconnect,
If the client because the exception, such as host computer suddenly loses power, or crash, at this time, because of using TCP, the server over a period of time, could not perceive the client has hang up,
Or abnormal program termination, at that time there will be no disconnection of the custom report
As the server is likely to know that the connection is broken)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
CliA -- "server -- -- -- -- --" cliB
Simple example header | the from | to | time | content |
Server parsed, whose message is sent to,
Query the database or yourself to achieve a hash index, find out cliB data information, to see if it online
If online, then find out the cli holdings of connection, to the forwarded message, [note may have to implement the application layer to received the confirmation message]
If not online, the server will be responsible for caching the message, and in the customer information in the table, each user must correspond to a list box [record how many offline messages when the user is offline, and set the upper limit, a user can have at most how many offline messages] when forwarding? When there are new customers connected to check the email address list, if there are offline messages, send
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Said about the train of thought, many details still need to your own design, it is recommended to use off-the-shelf database (such as mysql),
If you want to own implementation file storage, and a lot of data structure, is more complicated, a lot of details and realize the need to consider,

CodePudding user response:

I want to know

CodePudding user response:

Baotou, plus a few byte 0 broadcast data,
For 1 ~ n to forwarding data, and the connection number,

Server after the connection is established, [from the id in the pool, also can be used as the connection object in the connection pool an attribute] returns a number to the client, identify the connection id,

The client when A connection to upload their own user name, password authentication their identity, the establishment of connection id<- & gt; user identity mapping relationship, the server for the user's friends} {B, C, D, all friends find the user id, retrieve the connection id<- & gt; user identity mapping relation, if found to {B, C, D} online sending users A message

CodePudding user response:

Want to define some protocols, such as how to distinguish between each client and the server is responsible for forwarding,
Struct MSG {
UINT64 client_id_from;
UINT64 client_id_to;
UINT msg_length;
CHAR MSG [1]
};

CodePudding user response:

refer to the second floor yukint response:
need not mass, the server hold above all user's information, user ID as the index, can quickly locate the user information,
User information, including online state, whenever the cli to connect to the sever, cli active report a message [online], contains its own cliID,
User is offline, then there are two ways to realize the connection status updates, like online, cli reported an offline command (bring your own id, message format design],
If the server is disconnected, this time by connecting to, you are looking for a user id, your consideration, have the necessary to design the data structure,
(server active disconnect a client scenario is what? , such as a connection how long no news between us, whether its force disconnect,
If the client because the exception, such as host computer suddenly loses power, or crash, at this time, because of using TCP, the server over a period of time, could not perceive the client has hang up,
Or abnormal program termination, at that time there will be no disconnection of the custom report
As the server is likely to know that the connection is broken)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
CliA -- "server -- -- -- -- --" cliB
Simple example header | the from | to | time | content |
Server parsed, whose message is sent to,
Query the database or yourself to achieve a hash index, find out cliB data information, to see if it online
If online, then find out the cli holdings of connection, to the forwarded message, [note may have to implement the application layer to received the confirmation message]
If not online, the server will be responsible for caching the message, and in the customer information in the table, each user must correspond to a list box [record how many offline messages when the user is offline, and set the upper limit, a user can have at most how many offline messages] when forwarding? When there are new customers connected to check the email address list, if there are offline messages, send
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Said about the train of thought, many details still need to your own design, it is recommended to use off-the-shelf database (such as mysql),
If want to realize file storage, and a lot of data structure, is more complicated, a lot of details and realize the need to consider,

Ideas very thanks very clear there is a problem is the server received the message is forwarded to all clients to let the client to determine whether ID for your ID

CodePudding user response:

refer to 6th floor xsf_QianShi response:
Quote: refer to the second floor yukint response:

Need not mass, the server hold above all user's information, user ID as the index, can quickly locate the user information,
User information, including online state, whenever the cli to connect to the sever, cli active report a message [online], contains its own cliID,
User is offline, then there are two ways to realize the connection status updates, like online, cli reported an offline command (bring your own id, message format design],
If the server is disconnected, this time by connecting to, you are looking for a user id, your consideration, have the necessary to design the data structure,
(server active disconnect a client scenario is what? , such as a connection how long no news between us, whether its force disconnect,
If the client because the exception, such as host computer suddenly loses power, or crash, at this time, because of using TCP, the server over a period of time, could not perceive the client has hang up,
Or abnormal program termination, at that time there will be no disconnection of the custom report
As the server is likely to know that the connection is broken)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
CliA -- "server -- -- -- -- --" cliB
Simple example header | the from | to | time | content |
Server parsed, whose message is sent to,
Query the database or yourself to achieve a hash index, find out cliB data information, to see if it online
If online, then find out the cli holdings of connection, to the forwarded message, [note may have to implement the application layer to received the confirmation message]
If not online, the server will be responsible for caching the message, and in the customer information in the table, each user must correspond to a list box [record how many offline messages when the user is offline, and set the upper limit, a user can have at most how many offline messages] when forwarding? When there are new customers connected to check the email address list, if there are offline messages, send
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Said about the train of thought, many details still need to your own design, it is recommended to use off-the-shelf database (such as mysql),
If want to realize file storage, and a lot of data structure, is more complicated, a lot of details and realize the need to consider,

Ideas very thanks very clear there is a problem is the server received the message is forwarded to all clients to let the client to determine whether ID for your ID, please

As it is, the client pressure is too big? On the server side processing is ok

CodePudding user response:

Forwarded to all clients, it is not advisable, invalid forward amount is too large, serious waste with the server, the client resources,

CodePudding user response:

refer to 6th floor xsf_QianShi response:
Quote: refer to the second floor yukint response:

Need not mass, the server hold above all user's information, user ID as the index, can quickly locate the user information,
User information, including online state, whenever the cli to connect to the sever, cli active report a message [online], contains its own cliID,
User is offline, then there are two ways to realize the connection status updates, like online, cli reported an offline command (bring your own id, message format design],
If the server is disconnected, this time by connecting to, you are looking for a user id, your consideration, have the necessary to design the data structure,
(server active disconnect a client scenario is what? , such as a connection how long no news between us, whether its force disconnect,
If the client because the exception, such as host computer suddenly loses power, or crash, at this time, because of using TCP, the server over a period of time, could not perceive the client has hang up,
Or abnormal program termination, at that time there will be no disconnection of the custom report
As the server is likely to know that the connection is broken)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
CliA -- "server -- -- -- -- --" cliB
Simple example header | the from | to | time | content |
Server parsed, whose message is sent to,
Query the database or yourself to achieve a hash index, find out cliB data information, to see if it online
If online, then find out the cli holdings of connection, to the forwarded message, [note may have to implement the application layer to received the confirmation message]
nullnullnullnullnull
  • Related