我已经构建了一个基本的套接字聊天程序。当人们登录时,他们的名字会被添加到在线用户列表中(左侧)。当用户单击其他在线用户之一时,该名称应附加到顶部的div。但正如你所看到的那样:
div class =" well"> null(图片右上方区域)。
似乎服务器没有捕获列表中人员的姓名。 我错过了什么?
客户端:
var people = {};
socket.on("connection", function(client) {
client.on("join", function(name){
console.log("Someone joined the chat", name);
roomID = null;
people[client.id] = {"name" : name, "room" : roomID};
sizePeople = _.size(people);
sizeRooms = _.size(rooms);
socket.sockets.emit("update-peopleCount", {people: people, count: sizePeople});
socket.sockets.emit("update-people", {people: people});
socket.sockets.emit("roomList", {rooms: rooms, count: sizeRooms});
client.emit("updateToSelf", "You have connected to the server. Join or create room to chat");
client.broadcast.emit('updateToOthers', name + " is online.");
clients.push(client); //populate the clients array with the client object
});
client.on("whispering", function(id) {
var person = people[id];
client.emit("addWhispering", person);
console.log("Whisper caught");
});
服务器端:
public String getSDCARDiD()
{
String sd_cid = null;
try {
File file = new File("/sys/block/mmcblk1");
String memBlk;
if (file.exists() && file.isDirectory()) {
memBlk = "mmcblk1";
} else {
//System.out.println("not a directory");
memBlk = "mmcblk0";
}
Process cmd = Runtime.getRuntime().exec("cat /sys/block/"+memBlk+"/device/cid");
BufferedReader br = new BufferedReader(new InputStreamReader(cmd.getInputStream()));
sd_cid = br.readLine();
//System.out.println(sd_cid);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sd_cid;
}