Thanks Bardwell.
I'm getting to understand but have a few more questions.

> The main problem is that the sub-applet is not able to finish starting
> because the main applet hasn't gone into the event loop.  If you
> put the socket connecting code into an {after 5s do} instead of using
> {sleep 5s} then it works.

At first,let me make sure of a few things.

Is it right that each applet have its own event loop?

If so, can I think {sleep} procedure makes other applets slept.
I have thought the procedure has such effect on only its own thread and
other applets' thread can run separately.

> However it might be easier (and more reliable, since it won't break >
> due to the port already being in use) to just have the main applet
> make the AcceptorTCPSocket without using an assigned local-port, do
> {bind} and then create the sub-applet, passing it the local-port that
> the AcceptorTCPSocket automatically allocated by putting the port
> number in the query part of the Url.  But that might not match how you
> want your applets to be organized.

this idea is good. I'll try this.

>>{define-proc {accept-handler e:AcceptableSocketEvent}:void
>>    let sock:DataTCPSocket = {listener.accept}
> This could block, ideally you wrap the contents of the accept-handler
> proc in {try catch e:WouldBlockSocketException do } and call the
> accept with timeout = 0s.

Let me make sure of the socket communication methods.

when it's ok for applet to be blocked while communication process
is running, I can write as bellow.

  let listener:AcceptorTCPSocket
   = {AcceptorTCPSocket
          local-port = 6001


  let b:bool = true
  {while b do
    let sock:DataTCPSocket = {listener.accept}

    || do something

And when it's needed to use asynchronous communication method
I should write as bellow.

  let listener:AcceptorTCPSocket
   = {AcceptorTCPSocket
          local-port = 6001

  {define-proc {accept-handler e:AcceptableSocketEvent}:void

      let sock:DataTCPSocket = {listener.accept timeout = 0s}

    catch e:WouldBlockSocketException do
      || there isn't connection which should always exists
      || when this event is invoked.

Is these code written with right manner?

>>    {sender.shutdown DataSocketShutdownOption.input-output}
> I don't know what you are hoping to do with this, you really just need
> to do {sender.close} and {output.close}.

Honestly I don't understand enough about the usage of
{DataTCPSocket.close} and {DataTCPSocket.shutdown}.

Please tell me when each method should be used or shold not be used.



To unsubscribe from this list, send a mail to:
To contact a human list administrator, send a mail to:
To recieve a list of other options for this list, send a mail to:

Reply via email to