Hello,

Assuming that the issue of getting all the data in the socket is solved, I
find a state-machine pattern helpful. The pattern is as follows:

[State-Machine-Pattern-For-Async-Socket-Coordination]

Context: One verb to coordinate multiple send-receive communications over a
async socket.

Description:
1) Arrange the verb that coordinates the communication as a  state machine.
Simple implementation is using a select. control structure. The state can be
maintained as a global variable or at socket level buffer.
2) Ensure that each state transition ends with a state change and a send
message.
3) Add the verb to the socket-handler as a command-chain. On change of state
to a socket-ready-for-read, the data is read and passed to the verb for
execution.
4) The verb thus "wakes-up" and continues the send-receive sequence based on
the state information previously stored.
5) Bookkeeping with regard to state, addition and removal of verb in the
socket handler command chain completes the implementation

Other implementations: I have seen this pattern in libwww where the protocol
is implemented as a state-machine.

Regards,
Yuva



On Dec 21, 2007 3:54 PM, Yuvaraj Athur Raghuvir <[EMAIL PROTECTED]>
wrote:

> Hello,
>
> a) I have a socket_handler associated with a async socket
> b) I have a test verb that performs a series of communication calls -
> sends data, receives data, and decides on the next step based on data
> returned.
> c) The problem I face is that the execution of the next statement in the
> verb occurs before the data in the socket is read.
>
> Q: How to synchronize verb execution with socket communication when I use
> async mode on socket?
>
> Regards,
> Yuva
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to