I'm creating an application that needs to send and receive information from a web page through Sockets , the Java server I was able to do, but I do not understand much of JS , could you help me make the client that sends and receives messages in JavaScript for web and that connects to this server in Java I did?
Server code: Server.java
public static void main(String[] args) throws Exception {
System.out.println("Inicia servidor.");
ServerSocket server = new ServerSocket(3000);
System.out.println("Aguardando conexão.");
Socket socket = server.accept();
System.out.println("Conexão estabelecida.");
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
PrintStream out = new PrintStream(output);
while (true) {
String mensagem = in.readLine();
System.out.println(
"Mensagem recebida do cliente [" +
socket.getInetAddress().getHostName() +
"]: " +
mensagem);
if ("FIM".equals(mensagem)){
break;
}
out.println(mensagem);
}
System.out.println("Encerrando conexão.");
in.close();
out.close();
socket.close();
System.out.println("Encerrando servidor.");
server.close();
}