processone / xmpp-messenger-ios

iOS XMPP Messenger Framework
MIT License
219 stars 93 forks source link

Socket closed by remote peer #55

Closed taylorcressy closed 8 years ago

taylorcressy commented 8 years ago

Hey guys. I have been banging my head against wall with this issue for the last couple of days, so now here I am.

I am attempting to connect to my Ejabberd server (16.06) with the following c2s configuration:

`listen:

port: 5222
module: ejabberd_c2s
certfile: "/Applications/ejabberd-16.06/conf/server.pem"
#starttls: true
## To enforce TLS encryption for client connections,
## use this instead of the "starttls" option:
starttls_required: true
##
## Custom OpenSSL options
##
##protocol_options:
##  - "no_sslv3"
##   - "no_tlsv1"
max_stanza_size: 65536
shaper: c2s_shaper
access: c2s`

The server, for now, is just on my dev machine. So I am connecting to it as localhost. Now, in my AppDelegate I initialize OneChat and specify host / port / startTLSPolicy as such:

` OneChat.start(true, delegate: self) { (stream, error) in if let _ = error { print("Error opening one chat") } else { print("Successfully opened chat") } }

    OneChat.sharedInstance.xmppStream?.hostName = "127.0.0.1"
    OneChat.sharedInstance.xmppStream?.hostPort = 5222
    OneChat.sharedInstance.xmppStream?.startTLSPolicy = XMPPStreamStartTLSPolicy.Required`

In my ChatController I connect as such:

OneChat.sharedInstance.connect(username: String(format: "%s@%s", self.chatUsername!, ChatConversationsViewController.HOST), password: self.chatPassword!) { (stream, error) -> Void in if let _ = error { print("Failed to connect to XMPP server with \(self.chatUsername) and \(self.chatPassword)") let alertController = UIAlertController(title: "Sorry", message: "An error occured: \(error)", preferredStyle: UIAlertControllerStyle.Alert) alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in //do something })) self.presentViewController(alertController, animated: true, completion: nil) } else { print("Successfully Connected") } };

Firstly, my callbacks are never called for either the OneChat.start() / OneChat.sharedInstace.connect().

Secondly, the behavior I see is that when I connect my delegate's oneStreamDidConnect() gets called and then my oneStreamDidDisconnect() get's called immediately after. The error message I receive is "Socket closed by remote peer".

I put debug logging on the Ejabberd instance and I get the following:

2016-07-21 11:20:58.297 [debug] <0.613.0>@ejabberd_receiver:process_data:284 Received XML on stream = <<"<?xml version='1.0'?>">> 2016-07-21 11:20:58.298 [debug] <0.613.0>@ejabberd_receiver:process_data:284 Received XML on stream = <<60,115,116,114,101,97,109,58,115,116,114,101,97,109,32,120,109,108,110,115,61,39,106,97,98,98,101,114,58,99,108,105,101,110,116,39,32,120,109,108,110,115,58,115,116,114,101,97,109,61,39,104,116,116,112,58,47,47,101,116,104,101,114,120,46,106,97,98,98,101,114,46,111,114,103,47,115,116,114,101,97,109,115,39,32,118,101,114,115,105,111,110,61,39,49,46,48,39,32,116,111,61,39,32,226,128,158,226,136,158,14,1,39,62>> 2016-07-21 11:20:58.298 [debug] <0.614.0>@ejabberd_c2s:send_text:1852 Send XML on stream = <<"<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='10454082093091685755' from='localhost' version='1.0'>">> 2016-07-21 11:20:58.298 [debug] <0.614.0>@ejabberd_c2s:send_text:1852 Send XML on stream = <<"<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'></xml-not-well-formed></stream:error>">> 2016-07-21 11:20:58.298 [debug] <0.614.0>@ejabberd_c2s:send_text:1852 Send XML on stream = <<"</stream:stream>">>

I am sorry if this is an Ejabberd configuration error, but it's an "out of the box" configuration.

Thanks, tc

p.s. Excuse the formatting, I am terrible with it.

taylorcressy commented 8 years ago

How embarrassing. Ignore this. Was formatting username / password with "%s" instead of "%@". invalid symbols. Which was probably causing the xmpp stream to become improperly formatted..... Fun times.

baoluo commented 8 years ago

@taylorcressy Nice to know that you found your issue ;)