{ "X3D": {
    "encoding":"UTF-8",
    "@profile":"Immersive",
    "@version":"3.1",
    "@xsd:noNamespaceSchemaLocation":"https://www.web3d.org/specifications/x3d-3.1.xsd",
    "JSON schema":"https://www.web3d.org/specifications/x3d-4.0-JSONSchema.autogenerated.json",
    "head": {
        "meta": [
          {
            "@name":"title",
            "@content":"NetworkSensorConnectionPrototypes.x3d"
          },
          {
            "@name":"description",
            "@content":"Prototypes for NetworkSensor and Connection nodes"
          },
          {
            "@name":"creator",
            "@content":"Don Brutzman, Chris Thorne, Don McGregor, Shun-Yun Hu"
          },
          {
            "@name":"created",
            "@content":"14 March 2008"
          },
          {
            "@name":"modified",
            "@content":"2 January 2025"
          },
          {
            "@name":"warning",
            "@content":"under development"
          },
          {
            "@name":"reference",
            "@content":"NetworkSensorConnectionNodes.html"
          },
          {
            "@name":"reference",
            "@content":"http://www.xj3d.org/tutorials/general_sai.html"
          },
          {
            "@name":"reference",
            "@content":"https://www.web3d.org/x3d/specifications/ISO-IEC-CD-19775-2.2/Part02/X3D_SAI.html"
          },
          {
            "@name":"reference",
            "@content":"https://www.web3d.org/x3d/specifications/ISO-IEC-19777-2-X3DLanguageBindings-Java/Part2/X3D_Java.html"
          },
          {
            "@name":"subject",
            "@content":"Prototypes for NetworkSensor and Connection nodes"
          },
          {
            "@name":"identifier",
            "@content":"https://www.web3d.org/x3d/content/examples/Basic/Networking/NetworkSensorConnectionPrototypes.x3d"
          },
          {
            "@name":"generator",
            "@content":"X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit"
          },
          {
            "@name":"license",
            "@content":"../license.html"
          },
          {
            "@name":"translated",
            "@content":"20 April 2026"
          },
          {
            "@name":"generator",
            "@content":"X3dToJson.xslt, https://www.web3d.org/x3d/stylesheets/X3dToJson.html"
          },
          {
            "@name":"reference",
            "@content":"X3D JSON encoding: https://www.web3d.org/wiki/index.php/X3D_JSON_Encoding"
          }
        ]
    },
    "Scene": {
        "-children":[
          { "WorldInfo":
            {
              "@title":"NetworkSensorConnectionPrototypes.x3d"
            }
          },
          { "ProtoDeclare":
            {
              "@name":"NetworkSensor",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"enabled",
                      "@accessType":"inputOutput",
                      "@type":"SFBool",
                      "@value":true
                    },
                    {
                      "@name":"metadata",
                      "@accessType":"inputOutput",
                      "@appinfo":"X3DMetadataObject node type only",
                      "@type":"SFNode",
                      "-children":[
                        {
                          "#comment":"Metadata initialization node is NULL"
                        }
                      ]
                    },
                    {
                      "@name":"isActive",
                      "@accessType":"outputOnly",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"connection",
                      "@accessType":"initializeOnly",
                      "@appinfo":"Connection node only",
                      "@type":"SFNode",
                      "-children":[
                        {
                          "#comment":"Default Connection node goes here"
                        }
                      ]
                    },
                    {
                      "@name":"httpRequest",
                      "@accessType":"inputOnly",
                      "@type":"SFString"
                    },
                    {
                      "@name":"httpResponse",
                      "@accessType":"outputOnly",
                      "@type":"MFString"
                    },
                    {
                      "@name":"channelId",
                      "@accessType":"initializeOnly",
                      "@type":"SFString",
                      "@value":true
                    },
                    {
                      "@name":"textInput",
                      "@accessType":"inputOnly",
                      "@appinfo":"ROUTE StringSensor output here",
                      "@type":"SFString"
                    },
                    {
                      "@name":"textOutput",
                      "@accessType":"outputOnly",
                      "@appinfo":"ROUTE this output to Text node string field",
                      "@type":"MFString"
                    }
                  ],
                  "-children":[
                    {
                      "#comment":"TODO: how to handle user-defined fields?"
                    },
                    {
                      "#comment":"perhaps corresponding MFString arrays for fieldName, fieldType, fieldAccessType, fieldInitialValues"
                    },
                    {
                      "#comment":"for now we'll simply try to get a MFString field to work"
                    },
                    {
                      "#comment":"TODO: can we get consistent type for textInput?"
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    {
                      "#comment":"First node determines node type of prototype"
                    },
                    { "Script":
                      {
                        "@DEF":"NetworkSensorScript",
                        "@url":["NetworkSensorScript.class","https://www.web3d.org/x3d/content/examples/Networking/NetworkSensorScript.class"],
                        "field": [
                          {
                            "@name":"enabled",
                            "@accessType":"inputOutput",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"metadata",
                            "@accessType":"inputOutput",
                            "@type":"SFNode"
                          },
                          {
                            "@name":"isActive",
                            "@accessType":"outputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"connection",
                            "@accessType":"initializeOnly",
                            "@appinfo":"Connection node only",
                            "@type":"SFNode"
                          },
                          {
                            "@name":"httpRequest",
                            "@accessType":"inputOnly",
                            "@type":"SFString"
                          },
                          {
                            "@name":"httpResponse",
                            "@accessType":"outputOnly",
                            "@type":"MFString"
                          },
                          {
                            "@name":"channelId",
                            "@accessType":"initializeOnly",
                            "@type":"SFString"
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"enabled",
                                "@protoField":"enabled"
                              },
                              {
                                "@nodeField":"metadata",
                                "@protoField":"metadata"
                              },
                              {
                                "@nodeField":"isActive",
                                "@protoField":"isActive"
                              },
                              {
                                "@nodeField":"connection",
                                "@protoField":"connection"
                              },
                              {
                                "@nodeField":"httpRequest",
                                "@protoField":"httpRequest"
                              },
                              {
                                "@nodeField":"httpResponse",
                                "@protoField":"httpResponse"
                              },
                              {
                                "@nodeField":"channelId",
                                "@protoField":"channelId"
                              }
                            ]
                        }
                      }
                    },
                    {
                      "#comment":"Subsequent nodes do not render, but still must be a valid X3D subgraph"
                    }
                  ]
              }
            }
          },
          { "ProtoDeclare":
            {
              "@name":"Connection",
              "ProtoInterface": {
                  "field": [
                    {
                      "@name":"enabled",
                      "@accessType":"inputOutput",
                      "@type":"SFBool",
                      "@value":true
                    },
                    {
                      "@name":"metadata",
                      "@accessType":"inputOutput",
                      "@type":"SFNode",
                      "-children":[
                        {
                          "#comment":"Metadata initialization node is NULL"
                        }
                      ]
                    },
                    {
                      "@name":"isActive",
                      "@accessType":"outputOnly",
                      "@type":"SFBool"
                    },
                    {
                      "@name":"url",
                      "@accessType":"inputOutput",
                      "@type":"MFString",
                      "@value":["x3dp://localhost:80"]
                    },
                    {
                      "@name":"protocol",
                      "@accessType":"initializeOnly",
                      "@type":"SFInt32",
                      "@value":0
                    },
                    {
                      "@name":"timeOut",
                      "@accessType":"inputOutput",
                      "@type":"SFTime",
                      "@value":0
                    },
                    {
                      "@name":"secure",
                      "@accessType":"inputOnly",
                      "@type":"SFBool"
                    }
                  ],
                  "-children":[
                    {
                      "#comment":"1 for HTTP, 2 for HTTP 1.1, 3 for TCP/IP, 4 for UDP, 5 for multicast"
                    },
                    {
                      "#comment":"spec TODO: change these code numbers to string enumerations instead"
                    }
                  ]
              },
              "ProtoBody": {
                  "-children":[
                    {
                      "#comment":"First node determines node type of prototype"
                    },
                    { "Script":
                      {
                        "@DEF":"ConnectionScript",
                        "@url":["ConnectionScript.class","https://www.web3d.org/x3d/content/examples/Networking/ConnectionScript.class"],
                        "field": [
                          {
                            "@name":"enabled",
                            "@accessType":"inputOutput",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"isActive",
                            "@accessType":"outputOnly",
                            "@type":"SFBool"
                          },
                          {
                            "@name":"url",
                            "@accessType":"inputOutput",
                            "@type":"MFString"
                          },
                          {
                            "@name":"protocol",
                            "@accessType":"initializeOnly",
                            "@type":"SFInt32"
                          },
                          {
                            "@name":"timeOut",
                            "@accessType":"inputOutput",
                            "@type":"SFTime"
                          },
                          {
                            "@name":"secure",
                            "@accessType":"inputOnly",
                            "@type":"SFBool"
                          }
                        ],
                        "IS": {
                            "connect": [
                              {
                                "@nodeField":"enabled",
                                "@protoField":"enabled"
                              },
                              {
                                "@nodeField":"isActive",
                                "@protoField":"isActive"
                              },
                              {
                                "@nodeField":"url",
                                "@protoField":"url"
                              },
                              {
                                "@nodeField":"protocol",
                                "@protoField":"protocol"
                              },
                              {
                                "@nodeField":"timeOut",
                                "@protoField":"timeOut"
                              },
                              {
                                "@nodeField":"secure",
                                "@protoField":"secure"
                              }
                            ]
                        }
                      }
                    },
                    {
                      "#comment":"Subsequent nodes do not render, but still must be a valid X3D subgraph"
                    }
                  ]
              }
            }
          },
          {
            "#comment":"We'll put our initial example next. First the listener will output networked messages to a Text node"
          },
          { "Shape":
            {
              "-geometry":
                { "Text":
                  {
                    "@DEF":"MessageOutput",
                    "@string":["NetworkSensor messages will appear here"],
                    "-fontStyle":
                      { "FontStyle":
                        {
                          "@justify":["MIDDLE","MIDDLE"]
                        }
                      }
                  }
                },
              "-appearance":
                { "Appearance":
                  {
                    "-material":
                      { "Material":
                        {
                          "@ambientIntensity":0.25,
                          "@diffuseColor":[0.374008,0,0.748016],
                          "@shininess":0.4,
                          "@specularColor":[0.909091,0.909091,0.909091],
                          "@transparency":0.35
                        }
                      }
                  }
                }
            }
          },
          {
            "#comment":"Only need a single Connection definition for this example"
          },
          { "ProtoInstance":
            {
              "@name":"Connection",
              "@DEF":"OurNetworkChannel",
              "fieldValue": [
                {
                  "@name":"url",
                  "@value":["x3dp://localhost:80"]
                },
                {
                  "@name":"protocol",
                  "@value":1
                },
                {
                  "@name":"timeOut",
                  "@value":10
                }
              ],
              "-children":[
                {
                  "#comment":"protocol 1=http"
                }
              ]
            }
          },
          {
            "#comment":"Here is the listener that connects and sends strings to the Text node"
          },
          { "ProtoInstance":
            {
              "@name":"NetworkSensor",
              "@DEF":"TextListener",
              "fieldValue": [
                {
                  "@name":"connection",
                  "-children":[
                    { "ProtoInstance":
                      {
                        "@name":"Connection",
                        "@USE":"OurNetworkChannel"
                      }
                    }
                  ]
                },
                {
                  "@name":"channelId",
                  "@value":"78"
                }
              ]
            }
          },
          {
            "#comment":"TODO: once a single string can successfully be sent, insert an intermediate Script to remember last 10 strings"
          },
          { "ROUTE":
            {
              "@fromField":"textOutput",
              "@fromNode":"TextListener",
              "@toField":"string",
              "@toNode":"MessageOutput"
            }
          },
          {
            "#comment":"Now capture text from local keyboard, send to scenes listening to this network connection"
          },
          { "ProtoInstance":
            {
              "@name":"NetworkSensor",
              "@DEF":"TextSender",
              "fieldValue": [
                {
                  "@name":"connection",
                  "-children":[
                    { "ProtoInstance":
                      {
                        "@name":"Connection",
                        "@USE":"OurNetworkChannel"
                      }
                    }
                  ]
                },
                {
                  "@name":"channelId",
                  "@value":"78"
                }
              ]
            }
          },
          { "StringSensor":
            {
              "@DEF":"KeyboardDetector"
            }
          },
          { "ROUTE":
            {
              "@fromField":"finalText",
              "@fromNode":"KeyboardDetector",
              "@toField":"textInput",
              "@toNode":"TextSender"
            }
          },
          {
            "#comment":"done. we should now be able to type text and have it appear in the output for whoever's using the same scene."
          }
        ]
    }
  }
}