Home > Back-end >  On the client server two-way communication problems
On the client server two-way communication problems

Time:09-18

I just turn to do the background, now have a question want to ask next everybody a great god!

Between the client and server two-way communication he normally, if is based on the TCP socket, and if our model is: the client after each time the send if need access to the server's response, the client also can receive the server active push message,

Such a situation, you usually is how to deal with? Is a logo on the message encapsulation, the logo is the response for each request? Need to create a single socket, to receive the active push?

CodePudding user response:

UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUP

CodePudding user response:

Consider using TIdCmdTCPServer, TIdCmdTCPClient

CodePudding user response:

refer to the second floor DelphiGuy response:
consider using TIdCmdTCPServer, TIdCmdTCPClient

For what reason?

CodePudding user response:

This is more convenient, command/response types of applications using TCP Client/Server also do,

CodePudding user response:

To define a good dialogue between serving the guest protocol format,

CodePudding user response:

reference 5 floor BCBPLC reply:
good to define the format of the dialogue between agreement,

Is this ok?
My client want to receive the main message already, also want to receive the request and response message,
The incoming main must be to want to do a separate thread or asynchronous, receives the request and response messages to use synchronization to do, if you don't open multiple socket, how to implement multithreaded to operating the same socket data it at the same time,,,
Main thread, for example, we define the protocol format, judge not advocate, but this time have no way to recv receives a request response thread has to the data.

CodePudding user response:

Such as server response message, sends a string "serverResponse", actively push messages, is sending a string "serverPush,"
The client with a thread is also receiving treatment, such as receiving "serverResponse," send "readyForServerResponse" server receives is sent specific data, the client receives data,
The client receives "serverPush" is also similar, anyway, is the way to send and receive, is done with the custom of a string as the forerunner,

Individuals feel less trouble is, if the connection interruption, restore the connection, from how to interrupt the process of recovery, or to reconnect, a process from scratch, as when the first connection,

CodePudding user response:

If you receive a pilot string, then immediately receive data, the other party sent the forerunner strings can put the amount of data to be sent information coding,

There is a problem, that is, in a sending, receiving process, the pending client have new operation request, a little bit more simple to deal with this request command string can be put in queue delay to send, until the end of a process to send,

I think this is simple, practical should be more complex, actually can consult the Trojan source code, know about the process to deal with it,

CodePudding user response:

TCP protocol, can consider to use Indy controls,
If using UDP can also, of course, is to deal with a little more, found that send messages, no reply, then send the message again can, until there is response,
  • Related