Technology Sharing

STOMP protocol in websocket: sockjs-client and stompjs

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. Introduction

When using WebSockets for real-time communication, a common implementation is to use the STOMP protocol. STOMP (Simple Text Oriented Messaging Protocol) is a lightweight protocol that is commonly used for communication between clients and message brokers, such as WebSockets. The following is a detailed explanation, including the steps from connection, subscription, sending processing to closing, and why it can be used in stompClient.send Specify the message path in .

  1. Connect

In WebSocket, connecting is usually the first step, which establishes a communication channel between the client and the server.

const socket = new SockJS('/ws');
const stompClient = Stomp.over
  • 1