Anderson Meneses
asked on
Windows Service with UDP
I need to create a Windows Service to receive connections UDP and send a command back to server.
I have this code
I'm receiving this erro:
I have this code
protected override void OnStart(string[] args)
{
_mStarted = true;
_mWorkReceberComando = new Thread(ReceberComando);
_mWorkReceberComando.Name = "Recebimento Comando";
_mWorkReceberComando.Start();
}
private void ReceberComando()
{
_endPoint = new IPEndPoint(IPAddress.Any, _port);
var udpClient = new UdpClient(_endPoint);
while (_mStarted)
{
var remoteEp = new IPEndPoint(IPAddress.Any, 0);
var data = udpClient.Receive(ref remoteEp);
var receivedString = BitConverter.ToString(data);
var comandoByte = new ObterComandocAck(receivedString);
var ipEndereco = remoteEp.Address;
udpClient.Connect(ipEndereco.ToString(), _port);
udpClient.Send(comandoByte, comandoByte.Length);
Console.WriteLine(receivedString);
}
}
I'm receiving this erro:
An existing connection was forcibly closed by the remote host
HYRESULT -2147467259
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes I did.
I'm need to connect to a GPS tracker and that need to open the connection first then I need to send the response in the same connection.
I've changed code to this:
Open in new window
Thanks for your help.