0

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);
}
Floki
  • 271
  • 1
  • 5
  • 15
  • This type of error is usually down to a firewall, or nothing listening on that port on the target machine. Is the client running on the same machine as the server? Or are they traversing a network/the internet where firewalls could be in the way? See http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it for more information. – hynsey Jun 03 '15 at 08:36
  • the client machine is locally connected with my server.Its a punch in machine that gives us the punched in records and now i want to send flag back to that machine – Floki Jun 03 '15 at 08:51
  • OK. Please take a look at the solution in this article, it seems to be what you are looking for: http://stackoverflow.com/questions/20038943/simple-udp-example-to-send-and-receive-data-from-same-socket – hynsey Jun 03 '15 at 08:58

0 Answers0