Class wwWebSocket

The wwWebSocket class provides basic helpers to Web Connection's Web Socket implementation.

This class can:

  • Create an instance of Web Socket Message object
  • Ability to Send a Web Socket Message

This class can be used in two ways:

  • As incoming Message object in wwProcess::OnWebSocket(loSocket)
  • Standalone for sending a message outside of Web Connection

OnWebSocket Usage

foxpro
foxpro
FUNCTION OnWebSocket ************************************************************************ * OnWebSocket **************************************** *** Function: Fired when a Web Socket request comes in. *** Assume: loMsg.Message, loMsg.UserId, loMsg.GroupId *** Pass: loMsg - Incoming (loMsg.Message) from Socket *** loSocketBroadcast - Use to broadcast message to others *** Return: nothing ************************************************************************ LPARAMETERS loSocket as wwWebSocketMessage LOCAL lcMarkdown, loSocketMsg, loMsg *** This is the Socket Payload object loMsg = loSocket.oMessage DO CASE CASE loMsg.action == "broadcastchatmessage" loSocket.AddRecipient(loMsg.GroupId, "group") *** Parse incoming message as Markdown lcMarkdown = Markdown(loMsg.message) lcMarkdown = ALLTRIM(lcMarkdown) && RTRIM(LTRIM(lcMarkdown,0,"<p>"),"</p>") *** Change incoming message with updated HTML loMsg.message = lcMarkdown *** Broadcast the message loSocket.BroadcastMessage(loMsg) ENDCASE ENDFUNC * OnWebSocket

Standalone Usage

foxpro
foxpro
DO wwWebSockets loSocket = CREATEOBJECT("wwWebSockets") loSocket.cBaseUrl = "http://localhost:5200/" loMsg = loSocket.GetMessageObject() loMsg.userId = "RickFox" loMsg.Message = "Hello from FoxPro " + TIME() loMsg.action = "broadcastchatmessage" && send to everybody loSocket.BroadcastMessage(loMsg)

Class Members

MemberDescription
AddRecipient The wwWebSocket class provides basic helpers to Web Connection's Web Socket implementation. This class can: * Create an instance of Web Socket Message object * Ability to Send a Web Socket…
o.AddRecipient(lcUserOrGroup,lcType)
BroadcastMessage This method allows you to broadcast a message to connected Web Socket clients at the server you are targeting. The `loMsg` object can either be: * An incoming `loSocket.oMessage` object in…
o.BroadcastMessage(loMsg)
CreateMessageObject Creates a Web Socket message object the structure that is used to broadcast messages to all connected recipients. By default this method sets the `oMessage` instance as well as returning the…
o.CreateMessageObject(llDontAssign)
cBaseUrl The base URL to the Web Site to send to. Needs to be set when sending outside of Web Connection. Inside of Web Connection this value is automatically set based on the incoming request of the Web site.
oMessage An instance of a Message object created with `CreateMessageObject()`. The structure of this object is: ```js { // a routing action that allows the server or // client to differentiate messages …

See also

Class wwWebSocket

© West Wind Technologies, 2025 • Updated: 2025-03-12
Comment or report problem with topic