Я получаю сообщение об ошибке HostNotFound при попытке соединения с сокетом в async. Я уверен, что хозяин работает. Самая странная часть заключается в том, что весь эмулятор, начинающийся с «8.1 u1 *», не дает такой ошибки. Они соединяются без проблем. Только мое устройство (htc windows phone 8s) и эмуляторы без 8.1 получают эту ошибку. Адрес хоста 109.235.68.205 и порт 6005. Я нацелен на телефон с 8.0-окнами. У меня нет идей, как его решить.Windows phone silverlight socket HostNotFound error
public string Connect(string hostName, int portNumber)
{
string result = string.Empty;
// Create DnsEndPoint. The hostName and port are passed in to this method.
DnsEndPoint hostEntry = new DnsEndPoint(hostName, portNumber);
// Create a stream-based, TCP socket using the InterNetwork Address Family.
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Create a SocketAsyncEventArgs object to be used in the connection request
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = hostEntry;
// Inline event handler for the Completed event.
// Note: This event handler was implemented inline in order to make this method self-contained.
socketEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(delegate(object s, SocketAsyncEventArgs e)
{
// Retrieve the result of this request
result = e.SocketError.ToString();
// Signal that the request is complete, unblocking the UI thread
_clientDone.Set();
if(OnConnect != null)
OnConnect(true, new ConnectionEventArgs() { Response = result });
});
// Sets the state of the event to nonsignaled, causing threads to block
_clientDone.Reset();
// Make an asynchronous Connect request over the socket
_socket.ConnectAsync(socketEventArg);
// Block the UI thread for a maximum of TIMEOUT_MILLISECONDS milliseconds.
// If no response comes back within this time then proceed
_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
return result;
}
Вместо System.Net.Socket я начал использовать Windows.Networking.Socket, который работает лучше. Основная проблема, я думаю, с Windows Phone не сокет. Он может отказаться от соединения, когда он хочет освободить ресурс. Вы тоже ответите :) – valentasm