当前位置: 首页>>代码示例>>C#>>正文


C# IConnection.Connect方法代码示例

本文整理汇总了C#中IConnection.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.Connect方法的具体用法?C# IConnection.Connect怎么用?C# IConnection.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnection的用法示例。


在下文中一共展示了IConnection.Connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunClientSubscriber

        private void RunClientSubscriber(IConnection<SimpleMessage<int>, int> connection, IConnectionStubListener<SimpleMessage<int>, int> listener, ushort port)
        {
            listener.BindTo(new IPEndPoint(IPAddress.Any, port));
            var listenerTask = Task.Run(() => RunListenerSubscriber(listener));
            var ready = false;
            connection.Subscribe(0, (message, size) => ready = true);
            connection.Subscribe(1, (message, size) => TextMessageHandler("Client", message, size));
            connection.Connect(new IPEndPoint(IPAddress.Loopback, port));
            while (!ready)
                Thread.CurrentThread.Join(10);

            const int messages = 500;
            Console.WriteLine(@"Sending {0} messages with random data", 5);
            var rnd = new Random();
            for (var i = 0; i < messages; ++i)
            {
                var data = new byte[rnd.Next(16, 256)];
                rnd.NextBytes(data);
                connection.Send(new SimpleMessage<int>(1, Encoding.ASCII.GetBytes(Convert.ToBase64String(data))));
            }
            Console.WriteLine(@"Client: Done, sending exit message");
            connection.Send(new SimpleMessage<int>(2));
            connection.Disconnect();
            Console.WriteLine(@"Waiting for listener thread to exit");
            listenerTask.Wait();
            Console.WriteLine(@"Listener thread has exited");
            Console.WriteLine();
            Console.WriteLine(@"Press any key to exit");
            Console.ReadKey();
        }
开发者ID:Melamew,项目名称:iLynx.Common,代码行数:30,代码来源:TcpConnectionTests.cs

示例2: Connect

        public bool Connect()
        {
            
            if (_formatter == null)
            {
                throw new Exception("Channel formatter is not specified");
            }

            if (_eventListener == null)
            {
                throw new Exception("There is no channel event listener specified");
            }

            try
            {
                if (_connection == null)
                {
                    _connection = new TcpConnection();

                    if (!string.IsNullOrEmpty(_bindIP))
                        _connection.Bind(_bindIP);

                    _connection.Connect(_serverIP, _port);

                    _receiverThread = new Thread(new ThreadStart(Run));
                    _receiverThread.IsBackground = true;
                    _receiverThread.Start();
                    return true;
                }
            }
            catch (ConnectionException ce)
            {
                if (_traceProvider != null)
                {
                    _traceProvider.TraceError(Name + ".Connect", ce.ToString());
                }
                throw new ChannelException(ce.Message, ce);
            }

            return false;
        }
开发者ID:javithalion,项目名称:NCache,代码行数:41,代码来源:TcpChannel.cs

示例3: Connect

 /** \fn void Connect(string username, string password, ConfigOptions options)
  *  \brief Connect to remote Sequoiadb database server
  *  \username Sequoiadb connection user name
  *  \password Sequoiadb connection password
  *  \options The options for connection
  *  \return void
  *  \exception SequoiaDB.BaseException
  *  \exception System.Exception
  */
 public void Connect(string username, string password, ConfigOptions options)
 {
     ConfigOptions opts = options;
     if (username == null)
         username = "";
     if (password == null)
         password = "";
     this.userName = username;
     this.password = password;
     if (options == null)
         opts = new ConfigOptions();
     if (connection == null)
     {
         // single address
         if (serverAddress != null)
         {
             // connect
             try
             {
                 connection = new ConnectionTCPImpl(serverAddress, opts);
                 connection.Connect();
             }
             catch (System.Exception e)
             {
                 connection = null;
                 throw e;
             }
         }
         // several addresses
         else if (serverAddresses != null)
         {
             int size = serverAddresses.Length;
             Random random = new Random();
             int count = random.Next(size);
             int mark = count;
             do
             {
                 count = ++count % size;
                 try
                 {
                     ServerAddress conn = serverAddresses[count];
                     connection = new ConnectionTCPImpl(conn, opts);
                     connection.Connect();
                 }
                 catch (System.Exception)
                 {
                     if (mark == count)
                     {
                         throw new BaseException("SDB_NET_CANNOT_CONNECT");
                     }
                     continue;
                 }
                 break;
             } while(mark != count);
         }
         else
         {
             throw new BaseException("SDB_NET_CANNOT_CONNECT");
         }
         // get endian info
         isBigEndian = RequestSysInfo();
         // authentication
         try
         {
             Auth();
         }
         catch (BaseException e)
         {
             throw e;
         }
     }
 }
开发者ID:horizon3d,项目名称:SequoiaDB,代码行数:81,代码来源:Sequoiadb.cs


注:本文中的IConnection.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。