我已經在Visual Studio 2010和.NET 4.0做使用這個例子socketAsyncEventArgsWindows 8應用如何連接到插座服務器
的服務器。
現在我試圖從使用StreamSocket的Windows 8應用程序連接到它,但我得到了「Acces denied」消息。 這裏是客戶端代碼:
private StreamSocket streamSocket;
public string Server = "192.168.0.101";
public int Port = 9900;
public async void Connect()
{
streamSocket = new StreamSocket();
Connect();
try
{
await streamSocket.ConnectAsync(
new Windows.Networking.HostName(Server),
Port.ToString()); // getting Acces Denied here
DataReader reader = new DataReader(streamSocket.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
while (true)
{
var bytesAvailable = await reader.LoadAsync(1000);
var byteArray = new byte[bytesAvailable];
reader.ReadBytes(byteArray);
}
}
catch (Exception e)
{
MessageBox(e.StackTrace);
}
}
如何解決這個問題?有另一種使用此服務器發送和接收消息的方法嗎?
您是否檢查過Windows防火牆? – margabit