4D Blog

Home Product Injecting Custom Data In Websocket Client Headers

Injecting Custom Data In Websocket Client Headers

October 20, 2023

Product

Customizing WebSocket client headers lets you inject specific information, preferences, or requirements into the WebSocket connection establishment process.

From 4D v20 R3, you can transmit security information, application-specific data, or other data relevant to the server connection through websocket client headers.

Here is everything you need to know!

As described in the Websocket client blog post, you must create a class to manage the websocket events.

This class supports a new attribute, headers, which is an object where the attributes have this syntax: headers.key:=value.

For example, if you want to transmit an authorization token to the server, you need to create a class we’ll call WSConnectionHandler class :

Class constructor($myToken:Text)

// Creation of the headers sent to the server
This.headers:=New object ("x-authorization";$myToken)
// Cookie header should use this syntax:
This.headers.Cookie:="yummy_cookie=choco; tasty_cookie=strawberry"

Function onMessage($ws : Object; $event : Object)
   Form.messages.push($event.data)

Function onTerminate($ws : Object; $event : Object)
   Form.messages.push("Connection closed")
   

Check out the documentation for more details! And feel free to join the discussion on the 4D Forums.

Discuss

Tags 21, v20 R3, Websocket

Latest related posts

  • July 18, 2025

    Embed deployment license automatically into your applications

  • July 17, 2025

    New Class to Perform UDP Communications

  • July 17, 2025

    Managing Calendar Events with Microsoft 365 or Google in 4D: Create, Update, Delete

Fabrice Mainguené
Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R9 20 R10 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R9 20 R10 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy