Socket.io server written in Go that supports godot and hyperpad clients. This tutorial will guide you through setting up a Go Socket.IO server using the example provided in the Dangerbites/Go-Socket.io-Server-Example repository.
-
Create a new folder for your Go project.
-
Open your terminal and navigate to the folder.
-
Run the following command to initialize a Go module:
go mod init <your-module-name>
Replace
<your-module-name>with a name of your choice, e.g.,go-socketio-server.
To use Socket.IO in your Go project, you need to install the socket.io library. Run the following command in your terminal:
go get github.com/zishang520/socket.io/v2/socketThis will download and install the necessary dependencies.
-
Create a new file named
main.goin your project folder. -
Copy the code from the main.go file in the repository and paste it into your
main.gofile.Alternatively, you can download the
main.gofile directly from the repository and place it in your project folder. -
Add the
index.htmlfile:- Create a new file named
index.htmlin your project folder. - Copy the contents of the index.html file from the repository and paste it into your
index.htmlfile.
The
index.htmlfile is a simple client-side interface to interact with the Socket.IO server. - Create a new file named
Once the code is in place, you can run the server using the following command:
go run main.goThis will start the Socket.IO server on the default port (usually localhost:3000).
To test the server, open your browser and navigate to http://localhost:3000. You should see the index.html page, which allows you to send and receive messages via the Socket.IO server.
- If you're using a Godot client, ensure it is on version 4.0.x.
- Use this plugin, msabaeian/godot-socketio.
- If you're using a HyperPad client, ensure it is on version 3.0.x.
- If the connection doesn't work, try turning off the reconnect feature in the client.