Home > Back-end >  Delphi ClientSocket connection synchronization judgment
Delphi ClientSocket connection synchronization judgment

Time:10-01

So, to call B, then B will establish A Socket connection with the server C, B to C sends the message, feedback message to B, C, B back again to the A, the whole process needs to be synchronized, done namely wait to step on to the next step, B and C are creating A connection by now: ClientSocket. Open; To implement, and then through the ClientSocket. Active judging whether to True if there is any connection, ClientSocket. ClientType:=ctBlocking;
Problem is often appear not connected, or send messages to C B ClientSocket. When Active or False; Is to set the blocking the Open method or have a delay? How do I need to go to determine whether already connected, then go to send messages, give advice or comments,

CodePudding user response:

CtBlocking mode server to write multithreaded code,

CodePudding user response:

reference 1st floor hj3000 response:
ctBlocking mode server to write multithreaded code,

Is now it will be connected to the server for subsequent processing again, but it is not connected, may have already went down, how can sync?

CodePudding user response:

refer to the original poster suxiaolsx response:
, so A to call B, then B will establish A Socket connection with the server C, B to C sends the message, feedback message to B, C, B back again to the A, the whole process needs to be synchronized, or wait until the finish to do next step, B and C are creating A connection by now: ClientSocket. Open; To implement, and then through the ClientSocket. Active judging whether to True if there is any connection, ClientSocket. ClientType:=ctBlocking;
Problem is often appear not connected, or send messages to C B ClientSocket. When Active or False; Is to set the blocking the Open method or have a delay? How do I need to go to judge whether is connected, then go to send messages, to teach,


Comb your handling process, B is relative to A server is? Want to open A service to connect to A and B relative to C your B is A client is? B initiative to connect the C? Your transparent data forwarding, B side do not handle any agreement of the above things? Is A lost over what you throw it to the C?

CodePudding user response:

The
reference 3 floor fang098 response:
Quote: refer to the original poster suxiaolsx response:

So, to call B, then B will establish A Socket connection with the server C, B to C sends the message, feedback message to B, C, B back again to the A, the whole process needs to be synchronized, done namely wait to step on to the next step, B and C are creating A connection by now: ClientSocket. Open; To implement, and then through the ClientSocket. Active judging whether to True if there is any connection, ClientSocket. ClientType:=ctBlocking;
Problem is often appear not connected, or send messages to C B ClientSocket. When Active or False; Is to set the blocking the Open method or have a delay? How do I need to go to judge whether is connected, then go to send messages, to teach,


Comb your handling process, B is relative to A server is? Want to open A service to connect to A and B relative to C your B is A client is? B initiative to connect the C? Your transparent data forwarding, B side do not handle any agreement of the above things? Is A lost over what you throw it to the C?

B is not A server, it is an intermediate data handling process, and is A logic to handle things accordingly and not A message sent to C, C is the server, C treatment results back B will do the corresponding processing parsing again to the A,

CodePudding user response:

reference 4 floor suxiaolsx response:
Quote: reference fang098 reply: 3/f

The
Quote: refer to the original poster suxiaolsx response:

So, to call B, then B will establish A Socket connection with the server C, B to C sends the message, feedback message to B, C, B back again to the A, the whole process needs to be synchronized, done namely wait to step on to the next step, B and C are creating A connection by now: ClientSocket. Open; To implement, and then through the ClientSocket. Active judging whether to True if there is any connection, ClientSocket. ClientType:=ctBlocking;
Problem is often appear not connected, or send messages to C B ClientSocket. When Active or False; Is to set the blocking the Open method or have a delay? How do I need to go to judge whether is connected, then go to send messages, to teach,


Comb your handling process, B is relative to A server is? Want to open A service to connect to A and B relative to C your B is A client is? B initiative to connect the C? Your transparent data forwarding, B side do not handle any agreement of the above things? Is A lost over what you throw it to the C?

B is not A server, it is an intermediate process of data processing, and is A logic to handle things accordingly and not A message sent to C, C is the server, C treatment results back B will do the corresponding processing parsing again to the A,


Understand what you mean, you of the network communication, protocol data processing is in B, A is the UI should handle?? Your B to inform A in the form of data correction, if B is A DLL, very easy to do, how I need to go to determine whether have connected, then go to send messages, to teach, what you said is A peer-to-peer network communication, feeling is that you don't handle the business logic,

CodePudding user response:

reference 5 floor fang098 reply:
see what you mean, you of network communication, protocol data processing is in B, A is the UI should handle?? Your B to inform A in the form of data correction, if B is A DLL, very easy to do, how I need to go to determine whether have connected, then go to send messages, to teach, what you said is A peer-to-peer network communication, feeling is you don't handle the business logic,

First of all thank you for your answer, A call B correction is used, is mainly the connection B C requires connection to do down, but often haven't even do the following business,

CodePudding user response:

Procedure TCustomWinSocket. DoSetAsyncStyles;
Var
Msg: Integer;
Wnd: HWnd;
Blocking: Longint;
The begin
Msg:=0;
Wnd:=0;
If FAsyncStyles & lt;> [] then
The begin
Msg:=CM_SOCKETMESSAGE;
Wnd:=Handle;
end;
WSAAsyncSelect (FSocket, Wnd, Msg, Longint (Byte (FAsyncStyles)));
If FASyncStyles=[] then
The begin
Blocking:=0;
The ioctlsocket (FSocket FIONBIO, Blocking);
end;
end;
Look at the code, because TClientSocket WSAAsyncSelect communication model is used the ctBlocking set whether the SOCKET is blocked, but over here is to your application to
TCustomWinSocket=class
Private
FHandle: HWnd;
The FHandle window to send an asynchronous message, so what are you doing after returning synchronous TClientSocket active state or waiting for TClientSocket. FClientSocket. Connected state, waiting for the process to realize, you wait for it is best to add timeout handling inside, prevent online has not come here,
  • Related