-3

The whole point is to understand how computers should communicate with each other using javascript (no jQuery framework) and ajax (by using XMLHttpRequest). I have a memory game and I would like to add an online option for people so they can play with their friends. I was thinking about a peer 2 peer connection, but I didn't know how exactly and that is why I posted this question (I am sorry if my question is not meant to be here). This is what I had in mind:

User 1: 1. click->sendAction to server

Server: 1. receiveInfo->saveDetailsInDB 2. packReceivedInfo->send to User 2

User 2: 1. receiveInfo->updateDetails

Edit: Thanks to fstanis, I now know that I should use a WebSocket method in order to communicate users/computers with each other.

4

1 回答 1

2

直接回答这个问题 - 没有办法让两个用户直接使用 AJAX (XMLHttpRequest) 相互通信(例如,没有为他们中继消息的服务器)。XMLHttpRequest 要求您的用户之一运行 HTTP 服务器,并且浏览器不可能充当 HTTP 服务器。

您正在寻找的是WebSocket - 它允许您构建自己的客户端-服务器架构,独立于底层 HTTP 服务器。

于 2014-09-22T18:42:58.617 回答