【发布时间】:2016-05-21 04:21:47
【问题描述】:
首先,我希望你明白我的需要。 这是我当前的服务器端脚本:
var server = require('websocket').server, http = require('http');
var mysql = require('mysql');
var socket = new server({
httpServer: http.createServer().listen(8080)
});
var sql = mysql.createConnection({
host : 'localhost',
user : 'root',
password : ''
});
sql.connect(function(err) {
if (err) {
console.error('[MySQL] Error connecting: ' + err.stack);
return;
}
console.log('[MySQL] Connected as id ' + sql.threadId);
});
socket.on('request', function(request) {
var connection = request.accept(null, request.origin);
connection.on('message', function(message) {
connection.sendUTF(message);
});
connection.on('close', function(connection) {
console.log('connection closed');
});
});
客户端使用唯一查询连接到 websocket:
var WS = new WebSocket("ws://localhost:8080/steamid="+steamid);
现在是我需要的。 在服务器端,我需要获取客户端的 steamid 并保存,以便稍后在服务器中使用。例如,我需要获取 第 10 个客户的 Steamid。我相信这必须用数组来完成,但我对这些事情有点陌生。
提前致谢, 内达斯
【问题讨论】:
-
ws://localhost:8080/steamid=steamid看起来不像是一个有效的网址。我猜应该是这样的:ws://localhost:8080/?steamid=steamid?您的问题是如何访问该查询参数?那么这个问题可能会有所帮助:stackoverflow.com/questions/17301269/…
标签: javascript node.js websocket server steam-web-api