In my program I am trying to make the client send data over to the server and after this the data that was sent to the server is sent back to the client who sent the request originally. The only problem I am having is that once the data is sent over to the server it does not seem to want to be sent back to the client who sent it.client side:var name = document.getElementById("name_input").value; socket = io.connect("http://localhost:8080"); socket.emit("new-user", name); socket.on("welcome", function(data) { console.log("recived welcome"); }); Server sidevar name_list = ["bob", "sam", "jim"] io.on("connection", function(socket) { socket.on("new-user", function(data) { socket.emit('welcome', name_list); }); }); When I look at the console on the client side in my web browser, the message "received welcome" does not come up. With the socket.emit() on the server side, this makes me think that the data that the client sent over to the server will be sent directly back over to the client that sent it.
Submitted July 18, 2020 at 12:37PM by Digital_rookie
No comments:
Post a Comment