Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Socket.IO: How do i connect my Java client to my Javascript server?

I run a discord bot using node.js. I want to implement Socket.IO into the bot to send information over to my Java application.

For a test i just want to send over the number of members i have over

I host the bot on Glitch I use express in my bot so it is hosted like this

var express = require('express');
var app = express();
var http = require('http').createServer(app);
const io = require('socket.io')(http);
io.on('connection', client => {
    client.on('event', data => {
    console.log("Event recieved from client!");
})
}
app.listen(3000);

The client code looks like this

public static void main(String[] args) throws URISyntaxException {
   Socket socket = IO.socket("<glitch link>:3000");
   socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
   @Override
   public void call(Object... args) {
   socket.emit("event", "hello server!");
   socket.disconnect();
   });
socket.connect();

Comments