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


C# SocketClient.Connect方法代码示例

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


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

示例1: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SocketClient client = new SocketClient();
            string resposta;
            client.Connect("10.20.2.124", 6654);
            client.Send("nomejogador/" + txtblock1.Text + "/" + txtblock2.Text);
            resposta = client.Receive();
            /*if (resposta.StartsWith("<ERRO>"))
            {
                MessageBox.Show(resposta);
            }*/

            if (resposta == "naocadastrado")
            {
                MessageBox.Show("Cliente não cadastrado ou senha inválida!");
            }
            else if (resposta == "naook")
            {
                MessageBox.Show("Cliente já está logado no sistema!");
            }
            else
            {
                NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.RelativeOrAbsolute));
            }

        }
开发者ID:Bonei,项目名称:general-ifrn,代码行数:26,代码来源:MainPage.xaml.cs

示例2: isConnected

 private bool isConnected()
 {
     try
     {
         if (_client != null && _client.IsConnected)
             return true;
         var instance = new EventEndpointLocator().GetInstance(_path);
         if (instance == null)
             return false;
         _client = new SocketClient();
         _client.Connect(instance.Port, (m) => _handler(m));
         if (_client.IsConnected)
             return true;
         _client = null;
         return false;
     }
     catch
     {
         return false;
     }
 }
开发者ID:acken,项目名称:OpenIDE,代码行数:21,代码来源:PkgTestHandler.cs

示例3: ClassInitialise

        public static void ClassInitialise(TestContext context)
        {
            server = new SocketListener();
            server.Listen(port);

            client = new SocketClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port));

            client.Connected += (s, a) =>
            {
                connectedEvent.Set();
            };

            server.MessageReceived += async (s, a) =>
            {
                if (a.Message.MessageTypeId == 10)
                {
                    FakeNetworkRequest message;
                    if (JsonSocketMessage.TryParse(a.Message, out message))
                    {
                        a.SocketWriter.Send(11, new FakeNetworkResponse
                        {
                            Id = message.Id,
                            MessageDate = message.MessageDate,
                            Response = $"Hello, {message.Message}"
                        }, a.Message.Handle);                        
                    }
                }

                if (a.Message.MessageTypeId == 12)
                {                    
                    await a.Message.SaveAsAsync(sendFilePath);
                    sendFileEvent.Set();
                }
            };

            client.Connect();

            connectedEvent.WaitOne();
        }
开发者ID:elkdanger,项目名称:kilo,代码行数:39,代码来源:NetworkTests.cs

示例4: isConnected

		private bool isConnected()
		{
			try
			{
				if (_client != null && _client.IsConnected)
					return true;
				var instance = new EngineLocator().GetInstance(_path);
				if (instance == null)
					return false;
				_client = new SocketClient();
				_client.IncomingMessage += Handle_clientIncomingMessage;
				_client.Connect(instance.Port);
				if (_client.IsConnected)
					return true;
				_client = null;
				return false;
			}
			catch (Exception ex)
			{
				Debug.WriteError(ex.ToString());
				return false;
			}
		}
开发者ID:Azriel-S,项目名称:AutoTest.Net,代码行数:23,代码来源:EditorEngineLauncher.cs

示例5: StartSocketClient

 // start socket client
 private void StartSocketClient()
 {
     socketClient = new SocketClient();
     if (socketClient != null)
     {
         socketClient.ServerIP = serverIP;
         socketClient.ServerPort = serverPort;
         socketClient.DataReceivedInStringEvent += new DataReceivedInStringEventHandler(socketClient_DataReceivedEvent3);
         socketClient.DataReceivedInByteArrayEvent += socketClient_DataReceivedInByteArrayEvent3;
         socketClient.SocketErrorEvent += new SocketErrorEventHandler(socketClient_SocketErrorEvent3);
         socketClient.Connect();
         string message = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " SOCKET CLIENT START";
         SetText(message);
     }
 }
开发者ID:nhatkycon,项目名称:bxvinh,代码行数:16,代码来源:Form1.cs

示例6: DoRequest

        /// <summary>
        /// 
        /// </summary>
        /// <param name="host">远端主机地址</param>
        /// <param name="port"></param>
        /// <param name="route">远端执行方法名</param>
        /// <param name="param">参数</param>
        protected void DoRequest(string server, string param)
        {
            string[] serverArray = server.Split(':');
            using (SocketClient client = new SocketClient(serverArray[0], Convert.ToInt32(serverArray[1]), 4096))
            {
                client.ErrorHandle += DoError;
                client.ReceiveHandle += DoReceive;

                if (client.Connect())
                {

                    //param = GetRemoteParam(GameID, ServerID, param);
                    param = param + "&sign=" + GetSign(param);
                    param = HttpUtility.UrlEncode(param, Encoding.UTF8);
                    byte[] data = Encoding.UTF8.GetBytes(param);
                    data = BufferUtils.MergeBytes(BufferUtils.GetSocketBytes(data.Length), data);
                    client.Send(data);
                    client.ReceiveResult();
                }
            }
        }
开发者ID:rongxiong,项目名称:Scut,代码行数:28,代码来源:GameSocketClient.cs

示例7: canConnectTo

 private bool canConnectTo(Instance info)
 {
     var client = new SocketClient();
     client.Connect(info.Port, (s) => {});
     var connected = client.IsConnected;
     client.Disconnect();
     if (!connected)
         File.Delete(info.File);
     return connected;
 }
开发者ID:acken,项目名称:OpenIDE,代码行数:10,代码来源:PkgTestHandler.cs

示例8: InitializeClient

    void InitializeClient()
    {
        bufferManager = new BufferManager<byte>(1 << 8);
        client = new SocketClient(bufferManager);
        client.HostConnected += Client_HostConnected;
        client.HostDisconnected += Client_HostDisconnected;
        client.SendCompleted += Client_SendCompleted;
        client.NewDataReceived += Client_NewDataReceived;

        client.Connect("127.0.0.1", 1316);
    }
开发者ID:wang2124596,项目名称:Assets,代码行数:11,代码来源:NetManager.cs

示例9: canConnectTo

 private bool canConnectTo(Instance info)
 {
     var client = new SocketClient();
     client.Connect(info.Port, (s) => {});
     var connected = client.IsConnected;
     client.Disconnect();
     if (!connected) {
         try {
             Process.GetProcessById(info.ProcessID);
         } catch {
             File.Delete(info.File);
         }
     }
     return connected;
 }
开发者ID:continuoustests,项目名称:OpenIDE,代码行数:15,代码来源:PkgTestHandler.cs


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