我正在使用socket io v0.9.16我想更改套接字ID
io.on('connection', function(socket){
socket.id = 123;
io.sockets.sockets[123].emit('test'); // emit doesn't work
});
任何想法?我怎么能这样做
答案 0 :(得分:1)
您无需更改套接字的ID(事实上,这可能会破坏某些内容)。你想加入一个房间。这应该有效(假设你有一个客户端监听器用于' test'):
---
title: "Lord of the Rings"
author: "J. R. R. Tolkien"
header-includes:
- \usepackage{xcolor}
- \usepackage{fetamont}
- \newcommand*\eiadfamily{\fontencoding{OT1}\fontfamily{eiad}\selectfont}
- \newcommand{\mytitle}{\eiadfamily}
- \newcommand{\myauthor}{\ffmfamily \textcolor{blue}}
- \pretitle{\vspace{\droptitle}\centering\huge\eiadfamily}
- \preauthor{\centering\large\myauthor}
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Chapter 1
答案 1 :(得分:0)
SocketIO Docs说
Socket.IO中的每个Socket都由一个随机的,不可思议的唯一标识符Socket#id
标识。
所以也许你可以这样做。
var socket_list = [];
io.on('connection', function(socket){
socket_list[""+123] = socket.id;
io.sockets.sockets[socket_list[""+123]].emit('test');
});