1

There is backend spring boot and stomp(protocol under websocket)

So, I used oficial example from git https://github.com/spring-guides/gs-messaging-stomp-websocket And started it. I cat use js client from the example and can send messages - everything okey

enter image description here enter image description here

But I can't to send message from postman Successful connection, but messages doen't send to backend(no responses and can't to catch execution under debug controller)

enter image description here

enter image description here

How to correct send messages via stomp using postman?

1

1 Answer 1

2

You can send JSON message by Send Button with a specific channel.

Overview

enter image description here

Web Socket Server

Save as server.js

const express = require('express');
const { createServer } = require('http');
const { join } = require('path');
const { Server } = require('socket.io');

const app = express();
const server = createServer(app);
const io = new Server(server);

io.on('connection', (socket) => {
    console.log('a client connected');
    socket.emit('to_client', { message: 'Hello from server!' });

    // Listen a message from the client
    socket.on('to_server', (data) => {
        console.log('From client:', data);
        socket.emit('to_client', { message: `Server Received: ${JSON.stringify(data)}` });
    });
});

server.listen(3000, () => {
    console.log('server running at http://localhost:3000');
});

Install dependencies

npm install express socket.io

Run server

node server.js

enter image description here

Client Config in Postman

URL

ws://localhost:3000

To server channel (or topic)

to_server

To server payload

{ "name": "Nick", "data": 1234 }

To client channel (or topic)

to_client

enter image description here

Connect Server by Postman

enter image description here

Server-side

enter image description here

Send Message by Postman

enter image description here

Server-side

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

There is error message when try to connect to backend using postman when choose socket.io Could not connect to ws://localhost:8080/gs-guide-websocket 09:43:07 Error:{error} Handshake Details Request URL: localhost:8080/socket.io/?EIO=4&transport=websocket Request Method: GET
Can you try my server first?
With you server everything okey, but like additional question is postman doen't work with postman?
I try to connect with 'gs-messaging-stomp-websocket' by gradle bootRun. Browser open localhost:8080 works to send name and receive Greetings. I try to connect by Postman's WebSocket. It works send message and connection but It can't receive messages. Also I try to connect socket.io as same as my answer but It makes an error to GET connection. I think STORM web socket protocol can't handle by Postman Socket.IO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.