/// <summary> /// Connects to the listed server, disconnecting if currently connected. /// </summary> /// <param name="ServerAddress"></param> public void Connect(Uri ServerAddress) { // Create the client if needed if (_Client == null) { _Client = new TcpClient(); } // If we're already connected, close that connection and killit hard if (_Client.Connected) { _Client.Close(); CreateClient(); } // Now connect to the new stomp server _Client.Connect(Dns.GetHostAddresses(ServerAddress.Host)[0], ServerAddress.Port > 0 ? ServerAddress.Port : 8080); if (!_Client.Connected) { throw new InvalidOperationException("Failed to connect to server"); } if (UseStompPacket) { StompStompFrame Frame = new StompStompFrame(); Frame.Heartbeat = string.Format("{0},{0}", _Heartbeat); Frame.Hostname = ServerAddress.Host; Frame.Password = Password; Frame.Username = Username; SendFrame(Frame); } else { StompConnectFrame Frame = new StompConnectFrame(); Frame.Heartbeat = string.Format("{0},{0}", _Heartbeat); Frame.Hostname = ServerAddress.Host; Frame.Password = Password; Frame.Username = Username; SendFrame(Frame); } // Start the polling thread to handle heartbeats, etc _PollThread = new Thread(Run); _PollThread.Start(); }
/// <summary> /// Connects to the listed server, disconnecting if currently connected. /// </summary> /// <param name="ServerAddress"></param> public void Connect(Uri ServerAddress) { // Create the client if needed if (_Client == null) _Client = new TcpClient(); // If we're already connected, close that connection and killit hard if (_Client.Connected) { _Client.Close(); CreateClient(); } // Now connect to the new stomp server _Client.Connect(Dns.GetHostAddresses(ServerAddress.Host)[0], ServerAddress.Port > 0 ? ServerAddress.Port : 8080); if (!_Client.Connected) throw new InvalidOperationException("Failed to connect to server"); if (UseStompPacket) { StompStompFrame Frame = new StompStompFrame(); Frame.Heartbeat = string.Format("{0},{0}", _Heartbeat); Frame.Hostname = ServerAddress.Host; Frame.Password = Password; Frame.Username = Username; SendFrame(Frame); } else { StompConnectFrame Frame = new StompConnectFrame(); Frame.Heartbeat = string.Format("{0},{0}", _Heartbeat); Frame.Hostname = ServerAddress.Host; Frame.Password = Password; Frame.Username = Username; SendFrame(Frame); } // Start the polling thread to handle heartbeats, etc _PollThread = new Thread(Run); _PollThread.Start(); }