Dicom.Network.DcmSocket.Connect C# (CSharp) Method

Connect() public abstract method

public abstract Connect ( EndPoint remoteEP ) : void
remoteEP System.Net.EndPoint
return void
        public abstract void Connect(EndPoint remoteEP);

Same methods

DcmSocket::Connect ( string host, int port ) : void

Usage Example

Exemplo n.º 1
0
        private void Connect()
        {
            bool success = false;

            try {
                Log.Info("{0} -> Connecting to server at {1}:{2}", LogID, _host, _port);

                _socket = DcmSocket.Create(_socketType);
                _socket.ConnectTimeout = _connectTimeout * 1000;
                _socket.SendTimeout = _socketTimeout * 1000;
                _socket.ReceiveTimeout = _socketTimeout * 1000;
                _socket.ThrottleSpeed = _throttle;
                _socket.Connect(_host, _port);

                if (_socketType == DcmSocketType.TLS)
                    Log.Info("{0} -> Authenticating SSL/TLS for server: {1}", LogID, _socket.RemoteEndPoint);

                OnInitializeNetwork();

                _network = _socket.GetStream();
                success = true;
            }
            catch (SocketException e) {
                if (e.SocketErrorCode == SocketError.TimedOut)
                    Log.Error("{0} -> Connection timeout after {1} seconds", LogID, _connectTimeout);
                else
                    Log.Error("{0} -> Network error: {1}", LogID, e.Message);
                OnNetworkError(e);
                OnConnectionClosed();
            }
            catch (Exception e) {
            #if DEBUG
                Log.Error("{0} -> Processing failure: {1}", LogID, e.ToString());
            #else
                Log.Error("{0} -> Processing failure: {1}", LogID, e.Message);
            #endif
                OnNetworkError(e);
                OnConnectionClosed();
            }
            finally {
                if (!success) {
                    if (_network != null) {
                        try { _network.Close(); }
                        catch { }
                        _network = null;
                    }
                    if (_socket != null) {
                        try { _socket.Close(); }
                        catch { }
                        _socket = null;
                    }
                    _isRunning = false;
                }
            }

            if (success)
                Process();
        }