问题
I have been experimenting with JavaScript lately and was wondering if there was a way to send data from one computer to another on the same network. If there is, you do I use it?
回答1:
Sure there is, but you need a server for that. You cannot connect directly two computers' browsers over a network:
Computer A ---+
|
SERVER
|
Computer B ---+
The server's task will then be that of passing messages from one client to the other. You'll need PHP or C# (e.G. ASP.NET) for that. This topic is very (very) broad so this must suffice as an answer.
回答2:
You can go by a simple example of windows to windows communication. Go through the following link.
copy and paste server to server.js and client to index.html.
setup:
install socket.io
install client.io
link:
<https://www.tutorialspoint.com/socket.io/socket.io_broadcasting.htm>
来源:https://stackoverflow.com/questions/30562123/js-function-to-send-data-over-network