OpenMetaverse.Voice.TCPPipe.Connect C# (CSharp) Method

Connect() public method

public Connect ( string address, int port ) : SocketException
address string
port int
return System.Net.Sockets.SocketException
        public SocketException Connect(string address, int port)
        {
            if (_TCPSocket != null && _TCPSocket.Connected)
                Disconnect();

            try
            {
                IPAddress ip;
                if (!IPAddress.TryParse(address, out ip))
                {
                    IPAddress[] ips = Dns.GetHostAddresses(address);
                    ip = ips[0];
                }
                _TCPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPEndPoint ipEndPoint = new IPEndPoint(ip, port);
                _TCPSocket.Connect(ipEndPoint);
                if (_TCPSocket.Connected)
                {
                    WaitForData();
                    return null;
                }
                else
                {
                    return new SocketException(10000);
                }
            }
            catch (SocketException se)
            {
                return se;
            }
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="address"></param>
        /// <param name="port"></param>
        /// <returns></returns>
        public bool ConnectToDaemon(string address, int port)
        {
            daemonIsConnected = false;

            daemonPipe = new TCPPipe();
            daemonPipe.OnDisconnected +=
                delegate(SocketException e)
            {
                if (OnDaemonDisconnected != null)
                {
                    try { OnDaemonDisconnected(); }
                    catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, null, ex); }
                }
            };
            daemonPipe.OnReceiveLine += new TCPPipe.OnReceiveLineCallback(daemonPipe_OnReceiveLine);

            SocketException se = daemonPipe.Connect(address, port);

            if (se == null)
            {
                daemonIsConnected = true;

                if (OnDaemonConnected != null)
                {
                    try { OnDaemonConnected(); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); }
                }

                return(true);
            }
            else
            {
                daemonIsConnected = false;

                if (OnDaemonCouldntConnect != null)
                {
                    try { OnDaemonCouldntConnect(); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, null, e); }
                }

                Logger.Log("Voice daemon connection failed: " + se.Message, Helpers.LogLevel.Error);
                return(false);
            }
        }
All Usage Examples Of OpenMetaverse.Voice.TCPPipe::Connect