2013-02-08 200 views
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); 
      } 

     } 

回答

0

也許,你沒有在的tcp的NodeJS服務器的根目錄的文件clientaccesspolicy.xml。瞭解更多:http://msdn.microsoft.com/ru-ru/library/cc645032(v=vs.95).aspx

示例策略文件:

<?xml version="1.0" encoding ="utf-8"?> 
<access-policy> 
    <cross-domain-access> 
    <policy> 
     <allow-from> 
     <domain uri="file:///" /> 
     </allow-from> 
     <grant-to> 
     <socket-resource port="4530" protocol="tcp" /> 
     </grant-to> 
    </policy> 
    </cross-domain-access> 
</access-policy> 
相關問題