> Hi all.
> 
> I want to send xml data from a parent applet to a child applet
> through socket communication.
> 
> 
> So, for experiment, I made 2 applets as bellow.
> But they don't work at all...
> 
> As you see, send-to-local-app.dcurl tries to connect the port 6001
> on localhost.
> But CouldntConnectSocketException which says the attempt to connect
> to the port 6001 was refused always happens.
> 
> This is my first experience to use both AppletData and Socket at
> the same time and I have no idea to solve this problem at now.
> 
> Please tell me where is wrong.

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.

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.

Also, below I noted a few issues in the code that you sent.

> ---------------------------- listner.dcurl --------------------------
> {curl 4.0 applet}
> {curl-file-attributes character-encoding = "shift-jis"}
> 
> {import * from CURL.IO.SOCKET}
> 
> {let listener:AcceptorTCPSocket = {AcceptorTCPSocket
>                                       local-address = {SocketInetAddress
> SocketInetAddress.local-host},

Using local-host means that the socket is waiting on the one of the
external network interfaces (but only one).  If you want the socket to
be visable outside of the machine, you should just not set the
local-address, and it will listen on all network interfaces.  If you
want the socket to only be visable inside of the machine, then you should
use {SocketInetAddress SocketInetAddress.loopback}.

>                                       local-port = 6001
>                                   }
> }
> 
> {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 input:TranscodingTextInputStream = {TranscodingTextInputStream
>                                                {sock.to-InputStream}}
>     {while false == input.end-of-stream? do
>         let c:char = {input.read-one}
>         {output c}
>     }
> }
> 
> {do
>     {listener.add-event-handler
>         {on e:AcceptableSocketEvent do
>             {accept-handler e}
>         }
>     }
> 
>     {if listener.open? then
>         {listener.close}
>     }

This just looks wrong...

> 
>     {listener.bind}
> }
> 
> -------------------- send-to-local-app.dcurl ----------------------
> {curl 4.0 applet}
> {curl-file-attributes character-encoding = "shift-jis"}
> 
> {import * from CURL.ENGINE.BROWSER}
> {import * from CURL.IO.SOCKET}
> 
> {let another-applet:AppletData = {AppletData
>                                      null,
>                                      {url "listener.dcurl"}
>                                  }
> }
> 
> 
> {register-exit-proc {proc {}:void
>                         {another-applet.destroy}
>                     }
> }
> 
> {do
>     let s:String = "ABCDEFG"
>     let bv:ByteVec = {ByteVec max-size = 7}
> 
>     {encode-characters
>         s,
>         bv,
>         {get-character-encoding-by-name "shift-jis"}
>     }
> 
>     {sleep 5s}
> 
>     let sender:DataTCPSocket = {DataTCPSocket
>                                    remote-address = {SocketInetAddress
> SocketInetAddress.local-host},

See what I said above.  This could be slow if a machine has more than
one external network interface, because it might connect to the wrong
interface initially.

>                                    remote-port = 6001
>                                }
>     {sender.connect}
> 
>     let output:DataSocketByteOutputStream = {sender.to-OutputStream}
> 
>     {for i:int = 0 to 6 do
>         {output.write-one bv[i]}
>     }
> 
>     {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}.

> }
> 
> 
> 
> regards.
> --Maekawa

William Bardwell
[EMAIL PROTECTED]

*******************************************
To unsubscribe from this list, send a mail to:
mailto:[EMAIL PROTECTED]
To contact a human list administrator, send a mail to:
mailto:[EMAIL PROTECTED]
To recieve a list of other options for this list, send a mail to:
mailto:[EMAIL PROTECTED]

Reply via email to