Learn to Code via Tutorials on Repl.it!

← Back to all posts
Socket.io tutorial

Socket.io tutorial

In this tutorial you will learn socket.io java and how to make a chatroom
step 1: make a file called whatever you want for this example we will call it GroupChat.java, add a public class called whatever you named the file without the .java, add add these imports

then add

in the public class
then add a main method

step 2: make a main.sh file and a .replit, in the .replit write
run = "bash main.sh"
and in the bash file write

replace GroupChat with whatever the public class is, this code will run it so you don't have to go to shell, then add

for if they don't enter two values in the bash file
then add a else-try-catch in main method

those are the exceptions you have to catch, then add an InetAdress to the beginning of the try block

this will take the first value you entered on the bash file when it runs, then make an int called port, whcih is the second variable you enter when the bash file runs write after the InetAddress

then add this after it

then add

to set the name to the repl username
then add this

then, to send it frist add

then make a MulticastSocket

then add

then exit the public class and add all this

then add where we were in the public class, add

now for the main body of the chat, add

the ! things are for commands, I use them to change colors, leave, and other stuff and now for the filter and ban Filter add

to make the swear filter work add a file calle Swears.java, add

and add an array called wordsToRemove

add what words you want to filter in "" seperate with a , and for the ban list add the username of who you want to ban
add a file called AsciiArt.java and add

full code

I hope you enjoyed and if you know a better way to do ascii art please tell me
credits: @Ch1ck3n for the idea on how to make ascii art like @ruiwenge2 's socket.io tutorial