Giter VIP home page Giter VIP logo

socket-io's Introduction

socket-io

🃏socket.io实例,主要实现游戏通信

解决刷新浏览器即可连接游戏,超过两个人则返回人数已满信息

上一个版本,第一次当两个浏览器连接上服务器时,这个时候信息永久保存在了浏览器,所以这个时候刷新浏览器,浏览器会重新连接服务器。但是这个并不能连接上游戏。

第二个版本:通过users保存连接的客户端信息,当客户端退出时,user保存的信息会减少一个客户端信息。这个时候刷新浏览器会重新连上游戏。

第二版本新增:刷新客户端的棋子信息刷新,包括同步对方的棋子落子,以及被吃掉棋子时的同步。

爬坑

  1. 跨域

由于socket.服务器的端口和页面浏览器的端口不一样,导致跨域

  1. io('http://127.0.0.1:3001')和io('http://127.0.0.1:3001/chess')

使用io('http://127.0.0.1:3001/chess')连接能连接上,但是不能通信。(后台是用node写的,路径是/chess,貌似这个路径没什么用)

所以使用io('http://127.0.0.1:3001')能连接上并能通信

  1. 客户端向服务器端发送消息和服务器端向客户端发送信息

  2. 服务器端向指定客户端发送消息

  3. 服务器端获取连接的客户端信息

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.