multithreading - C++/CLI UdpClient multithreaded pool -
i start saying first multi-threaded software, polite :)
i have multithreaded application written in c++/cli uses pool of udpclient read from/write external hardware.
basically, there 3 threads: receiving thread, manages reception of messages incoming external hardware , puts them in parsing queue, parsing thread checks correctness of received messages , generates proper response put in sending queue, , sending thread continuously checks sending queue send enqueued messages external hardware.
as udpclients, use 2 of them: receiving client reception of incoming messages, , sending client send responses: due fact external hardware can change ip address @ runtime, receiving udpclient has listen on ip addresses, while sending client should send datagram specific ip address of external hardware. furthermore, receiving client has timeout value allows control connection status of external hardware.
here show example code receiving thread:
// receiving thread udpclient^ receivingclient = gcnew udpclient(ipaddress::any, 30303); // set timeout receivingclient->client->receivetimeout = 3000; // iteratively receive on ip::any , 30303 while(true) { try { array<byte>^ recmessage = receivingclient->receive(); // put message in parsing queue, global object parqueue->enqueue(recmessage); } catch (socketexception^ ex) { // handle timeout exception } }
please note exact ip address of external hardware ipendpoint of receiving client, , put in global variable called externalhardwareip
.
and here's example code parsing thread:
while(true) { if(parqueue->count > 0) { // method parse message , puts in sending queue parsemessage(parqueue->dequeue()); } }
finally, here's example code sending thread:
udpclient^ sendingclient = gcnew udpclient(externalhardwareip, 30303); while(true) { if(senqueue->count > 0) { sendingclient->send(senqueue->dequeue()); } }
now, think there several problems approach, appears sending operation on sending thread blocking whole application, preventing receiving thread receive message external hardware, , causing me headaches.
thanks in advance hints.
Comments
Post a Comment