public void Start(string server, string port) { try { session = new GameSession(); var tcpClient = new SimpleTcpClient().Connect(server, int.Parse(port)); Log("tcp client connected to server"); var handshakeCommand = new HandshakeCommand { me = $"player{new Random().Next(1000)} {punter.GetType().Name}" }; Log($"Begin handshake as {handshakeCommand.me}"); var reply = tcpClient.WriteAndGetReply(serializer.Serialize(handshakeCommand), TimeSpan.MaxValue); session.Status = GameStatus.Setup; tcpClient.DataReceived += TcpClient_DataReceived; var handshakeMessage = serializer.Deserialize <HandshakeMessage>(reply.MessageString); if (handshakeMessage.you != handshakeCommand.me) { throw new Exception($"me: {handshakeCommand.me}, you: {handshakeMessage.you}"); } } catch (Exception e) { Log(e.ToString()); } }
private void Form1_Load(object sender, EventArgs e) { client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += Client_DataReceived; this.myClient = new ClientTcp(); }
private void Client_Load(object sender, EventArgs e) { _client = new SimpleTcpClient { StringEncoder = Encoding.UTF8 }; _client.DataReceived += Client_DataReceived; }
private void ClientForm_Load(object sender, EventArgs e) { client = new SimpleTcpClient(); client.Delimiter = 0x0D; client.StringEncoder = Encoding.ASCII; client.DataReceived += Client_DataReceived; }
private void Form1_Load(object sender, EventArgs e) { //We must always description to new TcpClient because we will call its object below. client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; //Unicode Transformation Format..We encode the received data client.DataReceived += Client_DataReceived; //And we send the received data DataReceived object. }
//When the form loads private void Form1_Load(object sender, EventArgs e) { //Creates the TCP client client = new SimpleTcpClient { StringEncoder = Encoding.UTF8 }; client.DataReceived += Client_DataReceived; }
private void ChatWindowLoaded(object sender, EventArgs e) { client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += Client_DataReceived; txtStatus.IsReadOnly = true; txtHost.IsReadOnly = true; txtPort.IsReadOnly = true; }
private void Form1_Load(object sender, EventArgs e) { b_UnConnect.Enabled = false; client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += Client_DataReceived; server = new SimpleTcpServer(); server.Delimiter = 0x13; server.StringEncoder = Encoding.UTF8; server.DataReceived += Server_DataReceived; }
/// <summary> /// Connect to server with ip of server /// </summary> /// <param name="IP"></param> public void ConnectToServer(string IP) { try { SimpleClient = new SimpleTcpClient().Connect(IP, 9000); SimpleClient.DataReceived += SimpleClient_DataReceived; } catch (Exception er) { Logger.Log(er); MessageBox.Show(er.Message); } }
private void Form1_Load(object sender, EventArgs e) { try { client = new SimpleTcpClient(); //client.StringEncoder = Encoding.UTF8; string ip = Convert.ToString(txtHostClient.Text); int port = Convert.ToInt32(txtPortClient.Text); client.Connect(ip, port); client.DataReceived += Client_DataSender; // client.DataReceived += Client_DataReceivedDraw; } catch (Exception ex) { // Console.WriteLine("Listen thread exception!! " + ex.Message); } }
private void Client_Load(object sender, EventArgs e) { client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += clientDataRecieved; try { client.Connect(ip, Convert.ToInt32(port)); } catch { this.Hide(); MessageBox.Show("Could not connect to the server!" + Environment.NewLine + "Please ensure your firewall is disabled.", "Client", MessageBoxButtons.OK); Application.Exit(); } }
public static Message WriteAndGetReply(this SimpleTcpClient client, string data, TimeSpan timeout) { Message mReply = null; void onReceived(object s, Message e) => mReply = e; client.DataReceived += onReceived; client.Write(data); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); while (mReply == null && stopwatch.Elapsed < timeout) { Thread.Sleep(10); } client.DataReceived -= onReceived; return(mReply); }
private void ConnBtn_Click(object sender, RoutedEventArgs e) { if (client != null) { MessageBox.Show("접속중"); } else { try {//닉네임 공백 체크 //IP가 IP형식이 맞는지... if (int.TryParse(portTxt.Text, out int port) == false) { MessageBox.Show("포트 숫자 아님"); return; } //if (String.IsNullOrWhiteSpace(nickNameTxt.Text)) //{ // MessageBox.Show("닉네임 공백 있음"); return; //} //if(IPAddress.TryParse(ipTxt.Text,out IPAddress ip) == false) //{ // MessageBox.Show("IP 형식 아님"); return; //} client = new SimpleTcpClient(ipTxt.Text, port, nickNameTxt.Text); client.OnMessageReceived += Client_OnMessageReceived; client.Connect(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Form1_Load(object sender, EventArgs e) { client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; }
private void Client_Load(object sender, EventArgs e) { _CLIENT = new SimpleTcpClient(); _CLIENT.StringEncoder = Encoding.UTF8; _CLIENT.DataReceived += _CLIENT_DataReceived; }
private void btnConnect_Click(object sender, EventArgs e) { btnConnect.Enabled = false; tcpClient = new SimpleTcpClient().Connect(txtHost.Text, Convert.ToInt32(txtPort.Text)); btnSend.Enabled = true; }
private void btnConnect_Click(object sender, EventArgs e) { btnConnect.Enabled = false; client = new SimpleTcpClient().Connect("127.0.0.1", 8910); }
public void Form1_Load(object sender, EventArgs e) { Client = new SimpleTcpClient(); Client.StringEncoder = Encoding.UTF8; Client.DataReceived += Client_DataReceived; }
private void Login_Load(object sender, EventArgs e) { client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += Client_DataRecieved; }
private void ChatWindowLoaded(object sender, EventArgs e) { client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += Client_DataReceived; }
public Form1(SimpleTcpClient client1) { // TODO: Complete member initialization this.client = client1; InitializeComponent(); }