0

I have a server socket on Python and the client on React. I want to transmit plain text. But the client does not connect to the server socket. What I'm doing wrong ?. I've tried whit a client socket on python and It works but, not in this way. I appreciate any help

Server (Python)

import socket

s = socket.socket()
s.bind(('localhost', 8000))
s.listen(5)

while True:
    con, addr = s.accept()
    print("New connection")
    print(addr)
    con.send("Message")
    con.close()

Client (React)

import io from "socket.io-client";

  componentDidMount() {
    const socket = io("localhost:8000", {
      transports: ["websocket"],
      reconnection: true,
    });

    socket.on("connection", () => {
      this.setState({ isConnected: true });
    });

    socket.emit("Message to server", (data) => {
      console.log(data);
    });
  }
German M
  • 1
  • 3
  • 1
    `websocket` is different then `socket` [see](https://stackoverflow.com/questions/4973622/difference-between-socket-and-websocket) you have to use websocket library for server in python for easy use for [example](https://websockets.readthedocs.io/en/stable/intro.html) – gaurav Jun 12 '21 at 14:41
  • That was the problem. Thanks! – German M Jun 20 '21 at 23:18

0 Answers0