Giter Club home page Giter Club logo

Comments (5)

Allenxuxu avatar Allenxuxu commented on May 25, 2024

谢谢你分享的项目,最近在用gev和websocket做一个im的时候遇到一个问题,如何设计路由。我参考了你写的websocket例子,

type example struct{
	router map[int64]*connection.Connection // userId -> conn
}

router来维护整个用户和它连接的路由信息。
获取目标用户id,我是放在 OnMessage(c *connection.Connection, data []byte) 中第二个参数data中带进来的,就是说data数据也要结构化的,不知道这样做有没有问题啊?
另一个问题,OnClose(c *connection.Connection) 关闭一个连接的时候,只有conn,那如何在router里面清除这个连接归属用户的信息啊?还有用的网页在线websocket客户端断开连接的时候,好像没有触发OnClose,不知道是不是我改的有问题?
谢谢。

  • data数据本身就应该按自己的数据序列化使用
  • 第二个问题,我猜测是你的客户端没有真正断连接,建议你再测试一下

from gev.

yiippee avatar yiippee commented on May 25, 2024

你好,感谢你的回复。
gev自带的websocket例子,我测过多次,还是无法触发OnClose,好像一直卡死在 Connection 的 handleClose中,而且connected没连接。
另外,OnClose(c *connection.Connection) 关闭一个连接的时候,只有conn,那如何在router里面清除这个连接归属用户的信息啊?你提到ctx可以存储业务信息,但是这个ctx已经用于标识websocket是否upgrade了。

from gev.

Allenxuxu avatar Allenxuxu commented on May 25, 2024

你好,感谢你的回复。
gev自带的websocket例子,我测过多次,还是无法触发OnClose,好像一直卡死在 Connection 的 handleClose中,而且connected没连接。
另外,OnClose(c *connection.Connection) 关闭一个连接的时候,只有conn,那如何在router里面清除这个连接归属用户的信息啊?你提到ctx可以存储业务信息,但是这个ctx已经用于标识websocket是否upgrade了。

  • 你的是 mac 环境吗?
  • websocket 这个确实是我当初设计的不合理,刚改了一点,你可以看下这个 commit 117f75d ,改动不大。

from gev.

cs-charles avatar cs-charles commented on May 25, 2024

mac环境使用一些在线的ws连接工具(http://www.easyswoole.com/wstool.html),在手动关闭连接后并未触发OnClose()方法,请问这个是什么原因导致的。

from gev.

Allenxuxu avatar Allenxuxu commented on May 25, 2024

@cs-charles 可能是在线连接工具并没有断开链接

from gev.

Related Issues (20)

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.