0
我正在開發WP8應用程序。我必須做一個廣播,所以我在網上搜索,我發現無處不在這個示例代碼。無法使用WP8上的ReceiveFrom功能
public class RecvBroadcst
{
public static void Main()
{
Socket sock = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050);
sock.Bind(iep);
EndPoint ep = (EndPoint)iep;
Console.WriteLine("Ready to receive...");
byte[] data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref ep);
string stringData = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine("received: {0} from: {1}",
stringData, ep.ToString());
data = new byte[1024];
recv = sock.ReceiveFrom(data, ref ep);
stringData = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine("received: {0} from: {1}",
stringData, ep.ToString());
sock.Close();
}
我有一個問題與ReceivFrom我不能使用它,它不承認。我搜索了,我沒有發現有人說這個功能是不可能與原生WP8應用程序一起使用的。所以我很困惑和阻止,有人可以知道誰來解決這個問題嗎?
你見過[此示例](https://msdn.microsoft.com/en-我們/庫/窗/應用/ hh202864(v = vs.105)的.aspx)? –
@RowlandShaw我試過這個,但是我有一個錯誤'_socket.ReceiveFromAsync(socketEventArg);''它說**提供了一個無效的參數**。我無法理解爲什麼,所以我放棄了 –