I am using a punchin machine and fetching its data using UdpClient and it gives us perfectely but now i want to send flag back to that machine which one have sent us the datagrams.I am getting the IPAddress of sender machine in variable ipAddress and port number in portNo variable.But when i tried to use UdpClient.Connect or Udpclient.Send to send data to a specific ip then it gives No connection could be made because the target machine actively refused it How can i do it?
UdpClient udpServer = new UdpClient(7005);
var receivedResults = await udpServer.ReceiveAsync();
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there");
try
{
var ipAddress = Convert.ToString(receivedResults.RemoteEndPoint.Address);
var portNo = receivedResults.RemoteEndPoint.Port;
var endpoint = new IPEndPoint(IPAddress.Parse(ipAddress), portNo);
//udpServer.Connect(endpoint);
udpServer.Send(sendBytes, sendBytes.Length, endpoint);
}