0
我有一個簡單的nodejs Tcp服務器,它註冊每個客戶端並將每個消息從客戶端廣播到所有其他客戶端。Silverlight客戶端Node.js服務器 - 訪問被拒絕的錯誤
問題在於連接了silverlight套接字。當我嘗試連接到運行4530端口的公共IP運行nodejs Tcp服務器時,出現「拒絕訪問」錯誤。
代碼的NodeJS:
net = require('net');
var clients = [];
net.createServer(function (socket) {
socket.name = socket.remoteAddress + ":" + socket.remotePort
clients.push(socket);
socket.on('data', function (data) {
broadcast(data, socket);
});
socket.on('end', function() {
clients.splice(clients.indexOf(socket), 1);
});
function broadcast(message, sender) {
clients.forEach(function (client) {
if (client === sender) return;
client.write(message);
});
}
}).listen(4530);
的Silverlight代碼:
void Connect(string IP_Address)
{
client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs()
{
RemoteEndPoint = new IPEndPoint(IPAddress.Parse(IP_Address), 4530)
};
socketEventArg.Completed += OnConncetCompleted;
client_socket.ConnectAsync(socketEventArg);
}
void OnConncetCompleted(object sender, SocketAsyncEventArgs e)
{
if (e.SocketError == SocketError.Success)
{
this.Dispatcher.BeginInvoke(new ShowMessagedelegate(ShowMessageBox), "Connceted Successfully!");
this.Dispatcher.BeginInvoke(new Enabledelegate(EnableControl), true);
}
else
{
this.Dispatcher.BeginInvoke(new ShowMessagedelegate(ShowMessageBox), e.SocketError.ToString());
this.Dispatcher.BeginInvoke(new Enabledelegate(EnableControl), false);
}
}