Setup project Spring boot 2.x + Socket.io Client 4.x

Tram Ho

Hi, Today I will guide you to setup the simplest Java Spring boot + Socket.io Client project.

I have researched on the internet the tutorials on this topic, most of them guide to use this lib https://github.com/mrniko/netty-socketio .

There is a downside to it is that it is implemented on an existing Netty server, so if we use Spring boot to integrate, we will have to use 2 ports.

  • Making proj setup complicated when we have to configure 2 domains during dev and prod.
  • Difficulty in integrating security between Socket.io server and Spring security.

Without further ado, let’s get to work.

The familiar website of Springer dev. https://start.spring.io/

image.png

Dependencies:

  • JDK 17
  • Spring boot 2.x
  • Spring web
  • Websocket

This is the github of Socket.io java server

Please add this dependency.

image.png

Create proj dir according to ntn structure.

image.png

Classes.

Client

index.html

And here is the result. image.png github src: https://github.com/huyvu8051/springboot-socketio

Quick, isn’t it, if you have any questions plz leave comments. Thank you.

Share the news now

Source : Viblo