• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How rest api and web sockets can work together?

I found an example of a web socket from the Internet and I had a question that will help me in the implementation of my project

@Controller
@SendTo("/topic/greetings")

public class GreetingController {

@MessageMapping("/hello")
public Greeting greeting(HelloMessage message) throws Exception {
    Thread.sleep(1000); // simulated delay
    return new Greeting("Hello, name " + HtmlUtils.htmlEscape(message.getName()) + "!");
}



}

in this controller there is a name exchange and everything works correctly

@Configuration
@EnableWebSocketMessageBroker

public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableSimpleBroker("/topic");
    config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/gs-guide-websocket").withSockJS();
}

}

in my project I want to use rest api which will call the method in the controller

@Controller
@RequestMapping("/name")
public class SampleController {

GreetingController greetingController;

public SampleController() {
    greetingController = new GreetingController();
}

@PostMapping
public void name(@RequestBody HelloMessage helloMessage) throws Exception {
    greetingController.greeting(helloMessage);
}
}

When I call the method on api, I try to send a value on the socket so that everyone who subscribes receives this value. The controller that I wrote is an example. Is this possible?thanks in advance