objective c - Http event listener IOS(Persistent http connection) -


is there way create http listener in ios

httplistener: mean, create persistent http channel using post request, sever push events channel. want create channel wait server event.

-(void)httppost:(nsstring *)url andxml:(nsstring *)xml{     nshttpcookiestorage *cookiestorage = [nshttpcookiestorage sharedhttpcookiestorage];     nsurl *urls = [nsurl urlwithstring:url];     nsmutableurlrequest *request1 = [[nsmutableurlrequest alloc] initwithurl:urls];     nsdata *postdata = [xml datausingencoding:nsasciistringencoding allowlossyconversion:yes];     nsstring *username =[[applicationstorage applicationstorage] username];     nsstring *password = [[applicationstorage applicationstorage] password];       //http basic authentication     nsstring *authenticationstring = [nsstring stringwithformat:@"%@:%@", username, password];     nsdata *authenticationdata = [authenticationstring datausingencoding:nsutf8stringencoding];     nsstring *authenticationvalue = [authenticationdata base64encoding];     [request1 setvalue:[nsstring stringwithformat:@"basic %@", authenticationvalue] forhttpheaderfield:@"authorization"];     [request1 setvalue:@"text/xml" forhttpheaderfield:@"content-type"];          [request1 sethttpmethod:@"post"];       [request1 sethttpbody:postdata];      nserror *error = nil;     nshttpurlresponse *response = nil;     nsdata *data = [nsurlconnection sendsynchronousrequest:request1 returningresponse:&response error:&error];     nsstring* newstr = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];      nslog(@"httppostorput >>>>>>>>> response: %@",newstr);    // [[nsrunloop currentrunloop] run]; } 

i have created channel using above post request. channel close after creation

i have done in java

httpresponse objbwresponse = bwpost(string.format(xml_channel_creation, generatechannelsetid()), getbwserveraddress() + channel_creation_url);             if (objbwresponse != null && objbwresponse.getstatusline() != null && objbwresponse.getstatusline().getstatuscode() == 200) {                 // success                 log.w(log_tag, "xsi channel created succesfully");                 inputstream content = objbwresponse.getentity().getcontent();                  onchannelconnected(gchannelid);                 processmessage(content);             } else {                 // fail                 log.w(log_tag, "error in creating channel response: "+objbwresponse+" status code: "+(objbwresponse!=null?objbwresponse.getstatusline():"response null"));              }     private void processmessage(inputstream content) {         string responsexml;         document documentxml;         in = new bufferedinputstream(content);         stringbuilder stringbuilder = new stringbuilder();         try {             int input;             **while ((input = in.read()) != -1) {**                 stringbuilder.append((char) input);                  if (stringbuilder.indexof(channel_event_message_end_string) != -1) { 

thank you

amith


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -