Plugin with XMPP connection for file transfer error

I have been working on a plugin that can send and receive file transfers. To do so, I have the plugin create a registered connection with the Openfire server that handles all of the file transfer interaction. The connection is made just fine when I upload the plugin, however, if I restart the server I get the following error and the client connection is not established:

XMPPError connecting to 127.0.0.1:5222.: remote-server-error(502) XMPPError connecting to 127.0.0.1:5222.
– caused by: java.net.ConnectException: Connection refused: connect
at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection. java:830)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1276)
at services.model.connection.ModelServiceConnection.establishConnection(ModelServi ceConnection.java:140)

ModelServiceConnection.java at line 140 is:

134 ConnectionConfiguration connConfig;
135 connConfig = new ConnectionConfiguration(“127.0.0.1”, 5222);
136 connection = new XMPPConnection(connConfig);

137

138 try
139 {
140 connection.connect();
141 }

Any thoughts on why when the server is restarted it would deny the plugin from establishing an XMPPConnection with the server but the initial upload runs fine?

It appears that the connection for the contact can not be established when the plugin is initialized. I moved the connection call to occur the first time a message comes through and it works fine.

friend how did you solve it