{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-products/prep/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Connect to real-time events","description":"Hamilton's Developer Portal is used to help reference and understand the APIs of Hamilton products.","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"connect-to-real-time-events"},"children":["Connect to real-time events"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Prep provides real-time updates through WebSocket connections. The events WebSocket allows for monitoring system state changes, protocol execution progress, and other important notifications as they occur."]},{"$$mdtype":"Tag","name":"section","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{"className":"note"},"children":["Connecting to ",{"$$mdtype":"Tag","name":"span","attributes":{"className":"item"},"children":["WebSocket"]}," events enables your application to respond to system changes in real-time, providing a more efficient alternative to polling the REST API."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272457867","level":2},"children":["Connect to the events WebSocket "]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To connect to the events WebSocket, establish a WebSocket connection to the following endpoint:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"span","attributes":{"className":"file"},"children":["ws://[IP_address]/NimbusLite/instinctevents"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Replace ",{"$$mdtype":"Tag","name":"span","attributes":{"className":"code"},"children":["[IP_address]"]}," with the IP address of the Prep. Go to ",{"$$mdtype":"Tag","name":"a","attributes":{"className":"schema-iframe-link","href":"prep_guide_access_swagger"},"children":["Access OpenAPI documentation"]}," for instructions on finding the IP address."]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272459019","level":2},"children":["Log and review event formats "]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Because event documentation may be limited, log all incoming events to understand their structure and determine which events apply in your application."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To log events:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Establish a connection to the events WebSocket endpoint."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Set up a message handler that logs all incoming messages to the console or a file."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Perform various operations on the Prep (such as starting a protocol, run maintenance, or triggering errors)."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Review the logged events to identify their format and structure, and the conditions that trigger them."]}]}]},{"$$mdtype":"Tag","name":"section","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{"className":"note"},"children":["By logging events during different operations, you can build a comprehensive understanding of the event types available and their payloads."]}]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272460171","level":2},"children":["Example connection code "]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272463627","level":3},"children":["JavaScript "]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"const ws = new WebSocket('ws://[IP_address]/NimbusLite/instinctevents');\n\nws.onopen = () => { console.log('Connected to events WebSocket');\n};\n\nws.onmessage = (event) => { \n console.log('Event received:', event.data); \n const eventData = JSON.parse(event.data);\n};\n\nws.onerror = (error) => { \n console.error('WebSocket error:', error);\n\n};ws.onclose = () => { \n console.log('Disconnected from events WebSocket');\n};\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272464779","level":3},"children":["Python "]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":" import websocket\n import json\n \n def on_message(ws, message):\n   print(f\"Event received: {message}\")\n   event_data = json.loads(message)\n \n def on_error(ws, error):\n   print(f\"WebSocket error: {error}\")\n \n def on_close(ws, close_status_code, close_msg):\n   print(\"Disconnected from events WebSocket\")\n \n def on_open(ws):\n   print(\"Connected to events WebSocket\")\n\n\n ws = websocket.WebSocketApp(\n   \"ws://[IP_address]/NimbusLite/instinctevents\",\n   on_open=on_open,\n   on_message=on_message,\n   on_error=on_error,\n   on_close=on_close\n )\n\n\n ws.run_forever()\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272465931","level":3},"children":["C# "]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"c++","header":{"controls":{"copy":{}}},"source":" using System;\n using System.Net.WebSockets;\n using System.Text;\n using System.Threading;\n using System.Threading.Tasks;\n \n var ws = new ClientWebSocket();\n await ws.ConnectAsync(new Uri(\"ws://[IP_address]/NimbusLite/instinctevents\"), CancellationToken.None);\n \n Console.WriteLine(\"Connected to events WebSocket\");\n \n var buffer = new byte[1024 * 4];\n while (ws.State == WebSocketState.Open)\n {\n   var result = await ws.ReceiveAsync(new ArraySegment&amp;lt;byte&amp;gt;(buffer), CancellationToken.None);\n   var message = Encoding.UTF8.GetString(buffer, 0, result.Count);\n   Console.WriteLine($\"Event received: {message}\");\n }\n","lang":"c++"},"children":[]},{"$$mdtype":"Tag","name":"hr","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"id":"53272461323","level":2},"children":["Related WebSockets "]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In addition to the events WebSocket, the Prep also provides:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Errors WebSocket"]},": ws://[IP_address]/NimbusLite/instincterrors - For runtime error notifications. Go to ",{"$$mdtype":"Tag","name":"a","attributes":{"className":"schema-iframe-link","href":"prep_recipe_error_handling"},"children":["Error handling"]}," for more information."]}]}]}]},"headings":[{"value":"Connect to real-time events","id":"connect-to-real-time-events","depth":1},{"value":"Connect to the events WebSocket","id":"53272457867","depth":2},{"value":"Log and review event formats","id":"53272459019","depth":2},{"value":"Example connection code","id":"53272460171","depth":2},{"value":"JavaScript","id":"53272463627","depth":3},{"value":"Python","id":"53272464779","depth":3},{"value":"C#","id":"53272465931","depth":3},{"value":"Related WebSockets","id":"53272461323","depth":2}],"frontmatter":{"seo":{"title":"Connect to real-time events"}},"lastModified":"2026-07-30T19:22:04.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/pages/prep_guide_connect_realtime_events","userData":{"isAuthenticated":false,"teams":["anonymous"]}}