Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

demo application using stomp js and node js

package com.example.websocketdemo.controller;

import com.example.websocketdemo.model.ChatMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.stereotype.Controller;

@Controller
public class ChatController {

    @MessageMapping("/chat.sendMessage")
    @SendTo("/topic/public")
    public ChatMessage sendMessage(@Payload ChatMessage chatMessage) {
        return chatMessage;
    }

    @MessageMapping("/chat.addUser")
    @SendTo("/topic/public")
    public ChatMessage addUser(@Payload ChatMessage chatMessage, 
                               SimpMessageHeaderAccessor headerAccessor) {
        // Add username in web socket session
        headerAccessor.getSessionAttributes().put("username", chatMessage.getSender());
        return chatMessage;
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: Java socket connect to gmail 
Java :: what is the types of intent in android java 
Java :: Uri/Beecrowd problem no - 1146 solution in Java 
Java :: java coding standards for interfaces 
Java :: longadder 
Java :: java Optional to Collection 
Java :: java.lang.nullpointerexception (no error message) 
Java :: function compose method java 8 
Java :: fibonacci numbers using recursion in java 
Java :: rules for naming variables in java 
Java :: hystrix configuration spring boot 
Java :: excel data formatter in java 
Java :: node constructor 
Java :: how to divide coloumns in a text file into seperate arrays in java 
Java :: functionality of predicate functional interface in java 
Java :: https://java2blog.com/java-program-count-number-words-string/ 
Java :: how to search element in jtablejava 
Java :: java 8 anymatch two lists 
Java :: programically set data source properties in spring 
Java :: infinite loop in java 
Java :: Convert Java File to Kotlin File 
Java :: Execute method on load 
Java :: java tester si un caractere est une lettre 
Java :: adding new field in existing kibana index using spark java 
Java :: api for currency conversion free 
Java :: arraylist character agregar elementos en java 
Java :: activity show 1 time in android studio java 2022 
Java :: increasing the element without any replacement in java program 
Java :: pen default Mail Application in android studio java 
Java :: aws s3 client in java 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =