2
我想要做的是使用Windows.Networking.Sockets API獲取適用於Windows應用商店的基本界面。到目前爲止,我有這樣的:讓Windows Store Sockets與Netcat聊天?
public async void Test()
{
using (var socket = new StreamSocket())
{
socket.Control.KeepAlive = false;
socket.Control.NoDelay = false;
await socket.ConnectAsync(new HostName("192.168.1.1"), "5555", SocketProtectionLevel.PlainSocket);
using (var writer = new DataWriter(socket.OutputStream))
{
writer.UnicodeEncoding = UnicodeEncoding.Utf8;
writer.WriteString("yea!");
//writer.WriteByte(0x50); //this doesn't work either to send raw ASCII
var t = writer.FlushAsync();
while (t.Status != AsyncStatus.Completed) ; //just in case?
}
}
}
到目前爲止,我似乎確實成功連接和斷開。但是,我從來沒有收到任何文字。
我的netcat命令(OpenBSD的路由器下運行)
$ nc -lv 5555
如果我沒有netcat的運行,當我運行測試功能,它會拋出一個異常,一切按預期的方式。我在這裏做錯了什麼?