本文整理汇总了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));
}
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例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);
}
}
示例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();
}
}
}
示例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;
}
示例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);
}
示例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;
}