[zeromq-dev] ZMQ PUB-SUB problem
Amar Pol
amarpol1305 at gmail.com
Thu Jun 27 08:19:39 CEST 2013
Hello,
I am using zmq for ARM device on C- platform. And i am using DHCP as a
network mode.
My problem is as described follow.
I am using pub-sub protocol for my application and subscribers having dhcp
network mode. and communication is working very fine.
Now if some how *IP address of subscriber(biometric device in our case)
changes , communication breaks*.
subscriber not able to receive any command from publisher.
Is there any way to handle IP change in subscriber.
Here is the code I an using.
########################### subscriber.c
#####################################
int command_zmq=0,connect_flag=0;
char device_code[30],*sp;
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
int rec_data,i;
char add_buf[256];
char data_buf[256];
/*--------------------------------*/
if(zmq_connect (subscriber, Dev_Conf.ZMQ_URL) == 0)
{
connect_flag = 1;
zmq_setsockopt (subscriber,ZMQ_SUBSCRIBE,location_id,6);
zmq_setsockopt (subscriber, ZMQ_RCVTIMEO,"1000",4);
}
while(1)
{
command_zmq = 0;
read_wait();
if(connect_flag != 1)
{
if(zmq_connect (subscriber, Dev_Conf.ZMQ_URL) == 0)
{
connect_flag = 1;
zmq_setsockopt (subscriber,
ZMQ_SUBSCRIBE,location_id,6);
zmq_setsockopt (subscriber,
ZMQ_RCVTIMEO,"1000",4);
}
}
if(self_enroll_flag == FALSE && MenuStage == ZERO &&
StopZmq_Rec == FALSE)
{
if(connect_flag ==1){
memset(device_code,'\0',sizeof(device_code));
memset(add_buf,'\0',sizeof(add_buf));
memset(data_buf,'\0',sizeof(data_buf));
if(check_device_online() == 0 ){
zmq_recv (subscriber, add_buf, 256,
ZMQ_DONTWAIT);
zmq_recv (subscriber, data_buf,
256, ZMQ_DONTWAIT);
printf("\n Data is data_buf =%s
\n",data_buf);
if(strlen(data_buf) > 0)
{
command_zmq =
atoi((char*)(token_in_between(data_buf, '=', ',')));
sp =
(char*)(token_in_between(strstr(data_buf, "device_code"), '=', ','));
strcpy(device_code, sp);
}
}
}
if(strcmp(device_code,Dev_Conf.Device_ID)
== 0 || strcmp(device_code,"ALL") == 0)
{
init_server_flags();
set_operational_flag(command_zmq);
}
}
sleep(2);
}
zmq_close (subscriber);
zmq_ctx_destroy (context);
################################################################
--
Regards&Thanks
Amar Pol
Software Engineer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130627/7960642b/attachment.htm>
More information about the zeromq-dev
mailing list