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


C# IConnection.Open方法代码示例

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


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

示例1: Logon

		public void Logon(IConnection connection, string username, string password)
		{
			this.connection = connection; 
			connection.Closed += (sender, e) =>
			{
				this.EmitLoggedOut(null);
			};
			connection.Error += (sender, e) =>
			{
				this.EmitError(e.Exception);
			};
			connection.MessageReceived += new EventHandler<MessageEventArgs>(this.OnMessageReceived);
			connection.RaiseEvents = true;
			try
			{
				connection.Open();
			}
			catch (Exception ex)
			{
				this.EmitError(ex);
				this.EmitLoggedOut(null);
				return;
			}
			this.SendMessage(new MsgLogon()
			{
				Data =
				{
					Username = username,
					Password = password
				}
			});
		}
开发者ID:heber,项目名称:FreeOQ,代码行数:32,代码来源:Client.cs

示例2: AttemptConnect

 public bool AttemptConnect(string host, string portStr)
 {
     try
     {
         var port = Int32.Parse(portStr);
         RemoteHost = NodeBuilder.BuildNode().Host(host).WithPort(port).WithTransportType(TransportType.Tcp);
         Connection =
             new ClientBootstrap()
                 .SetTransport(TransportType.Tcp)
                 .RemoteAddress(RemoteHost)
                 .OnConnect(ConnectionEstablishedCallback)
                 .OnReceive(ReceivedDataCallback)
                 .OnDisconnect(ConnectionTerminatedCallback)
                 .Build().NewConnection(NodeBuilder.BuildNode().Host(IPAddress.Any).WithPort(10001), RemoteHost);
         Connection.Open();
         return true;
     }
     catch (Exception ex)
     {
         AppendStatusText(ex.Message);
         AppendStatusText(ex.StackTrace);
         AppendStatusText(ex.Source);
         return false;
     }
 }
开发者ID:KeithLee208,项目名称:helios,代码行数:25,代码来源:SocketClient.cs

示例3: SocketClient

 public SocketClient()
 {
     InitializeComponent();
     Connection =
             new ClientBootstrap()
                 .SetTransport(TransportType.Udp)
                 .RemoteAddress(Node.Loopback())
                 .OnConnect(ConnectionEstablishedCallback)
                 .OnReceive(ReceivedDataCallback)
                 .OnDisconnect(ConnectionTerminatedCallback)
                 .Build().NewConnection(NodeBuilder.BuildNode().Host(IPAddress.Any).WithPort(10001), RemoteHost);
     Connection.OnError += ConnectionOnOnError;
     Connection.Open();
 }
开发者ID:KeithLee208,项目名称:helios,代码行数:14,代码来源:SocketClient.cs

示例4: Main

        public static void Main()
        {
            // initialize display buffer
            _display = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);

            // sample "hello world" code
            _display.Clear();
            Font fontNinaB = Resources.GetFont(Resources.FontResources.NinaB);
            _display.DrawText("Waiting for data", fontNinaB, Color.White, 10, 64);
            _display.Flush();

            IChannel channel = new CSVChannel();
            _connection = new Connection("COM1", channel);
            _connection.OnReceived += _connection_OnReceived;
            _connection.Open();


            // go to sleep; all further code should be timer-driven or event-driven
            Thread.Sleep(Timeout.Infinite);
        }
开发者ID:nothingmn,项目名称:AGENT.Contrib,代码行数:20,代码来源:Program.cs

示例5: StartClient

 protected void StartClient()
 {
     if (!_server.IsOpen()) throw new HeliosException("Server is not started yet. Cannot start client yet.");
     _client = _clientConnectionFactory.NewConnection(_server.Local);
     _client.Receive += (data, channel) =>
     {
         if (!HighPerformance)
         {
             ClientReceiveBuffer.Add(data);
         }
         ClientReceived.GetAndIncrement();
     };
     _client.OnConnection += (address, channel) => channel.BeginReceive();
     _client.OnError += (exception, connection) => _clientExecutor.Exceptions.Add(exception);
     _client.Open();
 }
开发者ID:helios-io,项目名称:helios,代码行数:16,代码来源:MultiNodeTest.cs

示例6: Main

        static void Main(string[] args)
        {
            RemoteHost = NodeBuilder.BuildNode().Host("192.168.0.12").WithPort(9092).WithTransportType(TransportType.Tcp);

            kafkaClient =
                new ClientBootstrap()
                    .SetTransport(TransportType.Tcp)
                    .SetDecoder(new NoOpDecoder())
                    .SetEncoder(new NoOpEncoder())
                    .RemoteAddress(RemoteHost)
                    .OnConnect(ConnectionEstablishedCallback)
                    .OnDisconnect(ConnectionTerminatedCallback)
                    .Build().NewConnection(Node.Empty().WithTransportType(TransportType.Tcp), RemoteHost);

            kafkaClient.Open();

            //            TcpClient client = new TcpClient("192.168.0.12", 9092);

            Console.Title = string.Format("KafkaClient {0}", Process.GetCurrentProcess().Id);

            kafkaClient.OnError += KafkaClient_OnError;

            var request = new MetadataRequest(new List<string> { "test_topic" });
            var requestHeader = new RequestHeader((short)ApiKeys.Metadata, "Mr Flibble", 1234);

            var buffer = new MemoryStream();

            requestHeader.WriteTo(buffer);
            request.WriteTo(buffer);

            var bytes = buffer.ToArray();

            var lenght = KafkaTypesHelper.Int32;

            buffer = new MemoryStream();

            lenght.Write(buffer, bytes.Length);

            var writter = new BinaryWriter(buffer);

            writter.Write(bytes);

            Console.WriteLine("Bytes Lenght " + bytes.Length);

            bytes = buffer.ToArray();

            HexPrint(bytes);

            //kafkaClient.Receive += KafkaClient_Receive;
            //NetworkStream nwStream = client.GetStream();
            //nwStream.Write(bytes, 0, bytes.Length);
            kafkaClient.Send(new NetworkData() { Buffer = bytes, Length = bytes.Length });

            Thread.Sleep(5000);

            kafkaClient.Send(new NetworkData() { Buffer = bytes, Length = bytes.Length });

            /*byte[] bytesToRead = new byte[client.ReceiveBufferSize];

            int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);

            bytesToRead = bytesToRead.Take(bytesRead).ToArray();

            HexPrint(bytesToRead);

            bytesToRead = bytesToRead.Skip(8).ToArray();

            var s = ProtoUtils.parseResponse((short)ApiKeys.Metadata, new MemoryStream(bytesToRead));

            var response = new MetadataResponse(s);*/

            Console.WriteLine("Press any key to exit.");

            Console.ReadLine();
        }
开发者ID:rudygt,项目名称:dot-kafka,代码行数:75,代码来源:Program.cs

示例7: Internal_CreateHandler

        private FtpAdapterInboundHandler Internal_CreateHandler(string inputFolder, string filter, out IConnection connection)
        {
            var adapter = new FtpAdapter { PollingInterval = 15 };
            var connectionUri = GetFtpAdapterConnectionUri(inputFolder, filter);
            var factory = new FtpAdapterConnectionFactory(connectionUri, GetCredentials(), adapter);

            connection = factory.CreateConnection();
            connection.Open(TimeSpan.FromSeconds(30));

            var inputHandler = connection.BuildHandler<FtpAdapterInboundHandler>(null);

            inputHandler.StartListener(new string[0], TimeSpan.MaxValue);

            return inputHandler;
        }
开发者ID:mi-tettamanti,项目名称:mercury-contrib-adapters,代码行数:15,代码来源:Inbound.cs


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