Reputation:
after sending custom element i get disconnected.Is there a way? my code for connection
[self addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self setHostName:@"bowerchat.com"];
[self setHostPort:5222];
self.myJID = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@@bowerchat.com",UD_getObj(@"myPhoneNumber")]];
NSError * error;
[self connectWithTimeout:300 error:&error];
disconnected issue
Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer"
After found problem i changed @"type" parameter as @"type2" and it is working now...but i cannot find why?
-(void)sendMessageToServer:(NSDictionary*)paraDict{
NSString * userPhone = [[DBHelper sharedObject]getUserPhone:paraDict[@"friend_id"]];
NSXMLElement *a = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];
if(paraDict[@"type"] != nil){
NSMutableDictionary * k = [[NSMutableDictionary alloc]initWithDictionary:paraDict];
NSString * typeValue = [k[@"type"]copy];
[k removeObjectForKey:@"type"];
[k setObject:typeValue forKey:@"type2"];
paraDict = k;
}
XMPPElement *e = [[XMPPElement alloc] initWithName:@"message"];
for(NSString * key in paraDict.allKeys){
[e addAttributeWithName:key stringValue:paraDict[key]];
}
[e addAttributeWithName:@"to" stringValue:getJabberString(userPhone)];
[e addAttributeWithName:@"from" stringValue:getMyJabberString];
[e addChild:a];
NSLog(@"%@",[e attributesAsDictionary]);
[self sendElement:e];
}
Upvotes: 2
Views: 273
Reputation: 3316
Here's a good guideline on how to add custom data to your stanzas:
Do not:
- Add new attributes on the
<message>
,<iq>
or<presence>
elements.- Create new type values for stanzas.
- Create new top-level elements.
- Put your custom data in the
<body>
of a<message>
.- Invent new values for the
<show>
element in<presence>
stanzas (allowed values are listed in RFC 6121 section 4.7.2.1)Do:
Add a new XML element in your own namespace:
<message from='[email protected]/orchard' to='[email protected]/balcony' type='chat'> <data xmlns='https://example.im/my-awesome-new-xmpp-app'></data> </message>
Upvotes: 0
Reputation: 9055
The message type attribute is build into the XMPP protocol. It has a precise meaning on XMPP and you cannot put what you want as the value of the type message attribute. As defined in XMPP RFC, the only possible types are:
You cannot put anything in message type, or indeed, otherwise the server should disconnect you.
Reference: http://xmpp.org/rfcs/rfc6121.html#message-syntax-type
Upvotes: 2