Also, if you are just using sockets because you need a way to do RPC/IPC to the subapplets, there is a built in mechanism that may be easier to use. (This uses a field on the AppletData that lets the parent and child communicate over a RemoteConnection that is setup as part of running a sub-applet. It is also possible to make a SocketRemoteConnection with a socket that has been created by hand.)

(put all of those files in a directory on a web server and run parent.curl and you can see it talk to the children and see the child talk to the parent by typing in the text fields.)

(Thanks to BenH for the samples.)

William Bardwell
[EMAIL PROTECTED]
{curl 4.0 applet}
{curl-file-attributes character-encoding = "utf8"}

{include "ipc.scurl"}

|| For creating sub-applets.
{import * from CURL.ENGINE.BROWSER}

|| Allow graphical projecting of a child applet (as an "AppletGraphic"),
|| and also handle IPC from that child (as a "ParentInterface"), and, for
|| convenience, manage the "proxy" which can be used to communicate with
|| that child (as a "ChildInterface").
||
{define-class public final ChildGraphic
  {inherits ParentInterface, AppletGraphic}

  field public constant ident:String

  field public constant proxy:ChildProxy

  || See "ParentInterface".
  {method public {mention-string str:String}:String
    {popup-message "Got string from child <" & str & ">"}
    {return self.ident & ": " & str}
  }

  {constructor {default ident:String}

    set self.ident = ident

    || Prepare to project the child.
    {construct-super.AppletGraphic
        border-width = 1pt, border-color = "green"
    }

    || Create the child.
    let data:AppletData = {AppletData self, {url "child.curl"}} 

    || Get the connection to the child.
    let connection:RemoteConnection = data.inline-remote-connection

    || Allow communication to the child.
    set self.proxy = {ChildProxy connection, 0}

    || Handle incoming IPC from child.
    {ParentYxorp connection, 0, self}
  }
} 

{let child1:ChildGraphic = {ChildGraphic "child1"}}

{let child2:ChildGraphic = {ChildGraphic "child2"}}

{VBox
    background = "violet",
    width = 10cm,
    height = 6cm,
    margin = 5pt,
    spacing = 5pt,
    child1,
    child2
}

Set color for child1:
{TextField
    {on Action at tf:TextField do
        {remote-invoke-async
            {child1.proxy.set-color tf.value}
        }
    }
}

Set color for child2:
{TextField
    {on Action at tf:TextField do
        {remote-invoke-async
            {child2.proxy.set-color tf.value}
        }
    }
}
{curl 4.0 applet}
{curl-file-attributes character-encoding = "utf8"}

{include "ipc.scurl"}


|| The graphical content of this applet, and also handle IPC from the
|| parent (as a "ChildInterface"), and, for convenience, track the "proxy"
|| which can be used to communicate with the parent (as a "ParentInterface").
||
{define-class Widget {inherits VBox, ChildInterface}

  field public constant proxy:ParentProxy

  || See "ChildInterface".
  {method public {set-color color:String}:void
    set self.border-color = color
  }

  {constructor {default}

    {construct-super.VBox
        background = "cyan",
        border-color = "red",
        border-width = 2pt,
        spacing = 5pt,
        {TextField
            font-style = "italic",
            font-size = 12pt,
            {on Action at tf:TextField do
                {remote-invoke-async
                    {self.proxy.mention-string tf.value}
                 receiving result:String do
                    {popup-message "Parent sent back <" & result & ">"}
                }
            }
        }
    }

    || Get the connection to the parent.
    let connection:RemoteConnection =
        {get-the-applet}.inline-remote-connection

    || Allow communication to the parent.
    set self.proxy = {ParentProxy connection, 0}

    || Handle incoming IPC from parent.
    {ChildYxorp connection, 0, self}
  }
}

{Widget}

|| This file is included by both "parent.curl" and "child.curl".
|| It could be made into a package if desired.

{import * from CURL.REMOTE}


|| Define IPC from a child to its parent.
||
{define-remote-class public abstract open ParentInterface
  {define-remote-proxy-class ParentProxy}
  {define-remote-yxorp-class ParentYxorp}

  {remote-method public abstract open {mention-string str:String}:String}
}


|| Define IPC from a parent to its child.
||
{define-remote-class public abstract open ChildInterface
  {define-remote-proxy-class ChildProxy}
  {define-remote-yxorp-class ChildYxorp}

  {remote-method public abstract open {set-color color:String}:void}
}


*******************************************
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