我有这个代码:
// Load the TCP Library
net = require('net');
//var sys = require('sys');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
socket.name = socket.remoteAddress + ":" + socket.remotePort
// Put this new client in the list
clients.push(socket);
// Send a nice welcome message and announce
socket.write("Welcome " + socket.name + "\n");
broadcast(socket.name + " joined the chat\n", socket);
socket.write(tools.foo);
// Handle incoming messages from clients.
socket.on('data', function (data) {
broadcast(socket.name + " >> " + data+"\n", socket);
});
// Remove the client from the list when it leaves
socket.on('end', function () {
clients.splice(clients.indexOf(socket), 1);
broadcast(socket.name + " left the chat.\n");
});
// Send a message to all clients
function broadcast(message, sender) {
clients.forEach(function (client) {
// Don't want to send it to sender
if (client === sender) return;
client.write(message);
});
// Log it to the server output too
process.stdout.write(message)
}
}).listen(5100,"192.168.1.8");
// Put a friendly message on the terminal of the server.
console.log("Chat server running at port 5100\n");
使用 node.js。
实际上,它是一个简单的聊天服务器,我在其中开发了一个带有异步 tcp 套接字的 iOS 客户端,它与 telnet 客户端完美配合。
我会在 VisualBasic 中开发另一个客户端,但我尝试过的所有演示都在第一次连接时崩溃(其中一个)。
我该如何开始开发?