小编Mig*_*uel的帖子

在socket.io中管理多个选项卡(但相同的用户)

我有一些socket.io的问题,我不知道如何解决它.我有一个带有socket.io的登录系统的应用程序来管理用户交互.我还有一个数组来管理所有活动的websocket会话.此数组存储一对session.id => username.

当用户打开具有相同页面的新选项卡(或使用websocket的不同页面)时,问题就开始了.这会导致数组中的用户名条目重复.

{id1, username}
{id2, username}
Run Code Online (Sandbox Code Playgroud)

当套接字向用户发送消息时,它仅发送到该阵列的第一个会话ID,因此只有一个选项卡接收该消息.

我试图更改新连接的套接字ID以匹配另一个,但它不起作用.

socket.id = sessionId of the other websocket;
Run Code Online (Sandbox Code Playgroud)

我认为另一种解决方案是将消息发送到所有打开的会话,但我认为这不是最好的方法.

谢谢.

javascript session node.js socket.io

20
推荐指数
1
解决办法
2万
查看次数

从DataFrame到RDD [LabeledPoint]

我正在尝试使用Apache Spark MLlib实现文档分类器,并且我在表示数据时遇到了一些问题.我的代码如下:

import org.apache.spark.sql.{Row, SQLContext}
import org.apache.spark.sql.types.{StringType, StructField, StructType}
import org.apache.spark.ml.feature.Tokenizer
import org.apache.spark.ml.feature.HashingTF
import org.apache.spark.ml.feature.IDF

val sql = new SQLContext(sc)

// Load raw data from a TSV file
val raw = sc.textFile("data.tsv").map(_.split("\t").toSeq)

// Convert the RDD to a dataframe
val schema = StructType(List(StructField("class", StringType), StructField("content", StringType)))
val dataframe = sql.createDataFrame(raw.map(row => Row(row(0), row(1))), schema)

// Tokenize
val tokenizer = new Tokenizer().setInputCol("content").setOutputCol("tokens")
val tokenized = tokenizer.transform(dataframe)

// TF-IDF
val htf = new HashingTF().setInputCol("tokens").setOutputCol("rawFeatures").setNumFeatures(500)
val tf = htf.transform(tokenized)
tf.cache
val idf …
Run Code Online (Sandbox Code Playgroud)

scala apache-spark apache-spark-mllib

15
推荐指数
1
解决办法
1万
查看次数

Symfony/Doctrine:DateTime 作为主键

我正在尝试使用日期作为主键创建一个实体。问题是Symfony 无法将我使用的DateTime 转换为字符串以在IdentityMap 中引入它。在实体的持久化期间,我收到以下错误:

Catchable Fatal Error: Object of class DateTime could not be converted to string in..
Run Code Online (Sandbox Code Playgroud)

我在实体中使用此代码:

/**
 * @ORM\Id
 * @ORM\Column(type="datetime")
 */
protected $date;
Run Code Online (Sandbox Code Playgroud)

该错误出现在实体存储库中

$em = $this->getEntityManager();
$currentData = new CurrentData();
...
$currentData->setDate(new \DateTime($dateStr));
...
$em->persist($currentData);
$em->flush();
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?谢谢你。

datetime doctrine primary-key symfony

7
推荐指数
2
解决办法
4550
查看次数

递归删除多个socket.io侦听器

我正在使用node.js和socket.io编写应用程序,用户可以在个人聊天室中与对方交谈.每个人都可以拥有多个打开的聊天室.当用户想要退出聊天室时,系统必须删除该房间的每个套接字监听器.

websocket.on('createRoom', function(roomID) {
    ...
    var room = generateRoom();
    ...

    // Leaving room
    $('#exitButton').on('click', function() {
        // Removes
        websocket.removeAllListeners('createRoom');
    });

    // User joins the room
    websocket.on('main/roomJoin/'+roomID, function(username) {
        alert(username + ' has joined the room');
    });

    ...

    websocket.on('chat/messageReceived/'+roomID, function(message) {
        room.printMessage(message);
    });
});
Run Code Online (Sandbox Code Playgroud)

问题是removeAllListeners没有删除内部侦听器,因此如果另一个用户在另一个用户退出后进入该房间,他将收到警报.

另一种方法是将听众置于外面,但管理多个房间更加困难.

谢谢.

jquery listener node.js socket.io

3
推荐指数
1
解决办法
2892
查看次数