necesito obtener datagrama UDP desde asíncrono Socket Server, pero se produjo una excepción en mi solicitud:una conexión existente forzosamente fue cerrada por el host remoto
problema aparece allí:
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
El código fuente completo :
class Program
{
static void Main(string[] args)
{
const int PORT = 30485;
IPAddress IP;
IPAddress.TryParse("92.56.23.87", out IP);
// This constructor arbitrarily assigns the local port number.
UdpClient udpClient = new UdpClient(PORT);
Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
udpClient.Connect("92.56.23.87", PORT);
if (udpClient.Client.Connected)
Console.WriteLine("Connected.");
// Sends a message to the host to which you have connected.
Byte[] sendBytes = Encoding.ASCII.GetBytes("CONNECT");
udpClient.Send(sendBytes, sendBytes.Length);
//IPEndPoint object will allow us to read datagrams sent from any source.
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IP, PORT);
// Blocks until a message returns on this socket from a remote host.
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
// Uses the IPEndPoint object to determine which of these two hosts responded.
Console.WriteLine("This is the message you received " + returnData.ToString());
Console.WriteLine("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString());
udpClient.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
Excepción:
Connected.
System.Net.Sockets.SocketException (0x80004005): An existing connection
was forcibly closed by the remote host at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint& remoteEP) at ystem.Net.Sockets.UdpClient.Receive(IPEndPoint& remoteEP) at ConsoleApplication7.Program.Main(String[] args) in c:\users\user\documents\visual studio 2010\Projects\ConsoleApplication7\ConsoleApplication7\Program.cs
¿Cuál puede ser el problema?
para proporcionar más información, compré la conexión calcetines privada en esta página: http://rapidsocks.com/ estos servicios me dan una lista de IP y el puerto que en realidad no es un proxy .. sólo una conexión que me dan una proxyIP: proxyPort de un grupo en el servidor en respuesta ...
¿Cómo obtener esa respuesta con proxyIP: proxyPort desde el servidor?
buena pregunta - tal vez si nos dice un poco más - donde se produce la excepción? ¿Ves alguno de tus "mensajes de depuración" en la consola? ¿Puedes mostrarnos una prueba de ejecución? – Carsten
Haga una impresión de stackTrace en el bloque catch y vea qué línea está lanzando la excepción. – Zenwalker
el * otro lado * funciona correctamente, ¿o sí? ¿Puedes verificar esto? – Carsten