public void Connect() { tcpClient = new SimpleTcpClient().Connect(serverip, serverport); tcpClient.DelimiterDataReceived += (sender, msg) => { ReceivedMessage(sender, msg); }; }
public void Receive_Message_From_Client_Correctly() { var messageSentToServer = "This is not what it looks like"; var messageSentToServerBytes = Encoding.ASCII.GetBytes(messageSentToServer); var messageReceived = string.Empty; var server = SimpleTcpServer.Configure() .WithPort(Port) .OnClientRequest((data, send) => { messageReceived = Encoding.ASCII.GetString(data); Completion.Set(); }) .Start(); var client = SimpleTcpClient.Configure() .WithEndpoint(IpAddress, server.Port) .Connect(); client.Send(messageSentToServerBytes); Completion.WaitOne(); messageSentToServer.ShouldBe(messageReceived); server.Stop(); }
private void Form1_Load(object sender, EventArgs e) { client = new SimpleTcpClient("127.0.0.1:8001"); client.Events.Connected += Events_Connected; client.Events.DataReceived += Events_DataReceived; client.Connect(); }
public Engraver() { client = new SimpleTcpClient(); client.Connect(ip, port); client.StringEncoder = Encoding.ASCII; client.DataReceived += Client_DataReceived; }
private void Form1_Load(object sender, EventArgs e) { client = new SimpleTcpClient("127.0.0.1:8001"); client.Events.Connected += Events_Connected; client.Events.DataReceived += Events_DataReceived; gameRulesPB.Visible = false; }
private void Form1_Load(object sender, EventArgs e) { client = new(txtIpPort.Text); client.Events.Connected += Events_Connected; client.Events.DataReceived += Events_DataReceived; client.Events.Disconnected += Events_Disconnected; }
private void NewClient_OnReceivedMessage(object sender, MessageArgs e) { SimpleTcpClient senderClient = sender as SimpleTcpClient; Console.WriteLine("[TCPServer] New message received from: " + senderClient.Remote.Address.ToString() + ":" + senderClient.Remote.Port.ToString()); Console.WriteLine("[TCPServer] message: " + Encoding.ASCII.GetString(e.Message).Trim()); }
public WaitingRoom(string name, int conNum) { IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName()); ipAdress = localIPs[2].ToString(); string temp = ""; for (int i = 0, a = 0; i < ipAdress.Length; i++) { if (ipAdress[i] == '.' && ++a == 3) { ipAdress = ipAdress.Substring(0, i + 1) + conNum.ToString(); temp = conNum.ToString(); break; } } ip = IPAddress.Parse(ipAdress); InitializeComponent(); this.Text += temp; this.name = name; this.who = "client"; client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += GetClient; client.Connect(ipAdress, 8000); startMulti.Visible = false; }
public void startClient(string ip) { client = new SimpleTcpClient().Connect(ip, 8910); gameSendTimer.Start(); playerHasBall = true; ballDirection = 0; }
public MainWindow() { InitializeComponent(); _client = new SimpleTcpClient().Connect("192.168.0.222", 9670); _client.DataReceived += _client_DataReceived; Title = _client.TcpClient.Connected.ToString(); }
public SoIPClientRGBDevice(SoIPClientRGBDeviceInfo deviceInfo) { this.DeviceInfo = deviceInfo; _tcpClient = new SimpleTcpClient(); _tcpClient.DelimiterDataReceived += TcpClientOnDelimiterDataReceived; }
private void Form1_Load(object sender, EventArgs e) { wlctxt.Text = "Welcome " + username + "!"; client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.DataReceived += Client_DataReceived; }
public ChannelsView(string serverIP, string login) { InitializeComponent(); this.serverIP = serverIP; this.login = login; channelList = new List <Channel>(); ring = new System.Media.SoundPlayer(); ring.SoundLocation = "q.wav"; ring2 = new System.Media.SoundPlayer(); ring2.SoundLocation = "beep.wav"; ring3 = new System.Media.SoundPlayer(); ring3.SoundLocation = "neck.wav"; //Ozeki if (k == null) { k = new Klient(); } //TCP client = new SimpleTcpClient(); client.StringEncoder = Encoding.UTF8; client.Connect(serverIP, 8910); client.DataReceived += Client_DataReceived; client.WriteLine(diffieHellman.EncryptMessage("HI;")); label5.Text = "0"; btn_endCall.Visible = false; }
internal CommunicationHandler(string ipPort, PluginEventHandler pluginEventHandler) { _ipPortEndpoint = ipPort; TcpClient = new SimpleTcpClient(_ipPortEndpoint); TcpClient.Keepalive.TcpKeepAliveRetryCount = 5; TcpClient.Keepalive.EnableTcpKeepAlives = true; _pluginEventHandler = pluginEventHandler; TcpClient.Events.Connected += OnConnectedToHost; TcpClient.Events.Disconnected += OnDisconnectedFromHost; TcpClient.Events.DataReceived += OnReceivedData; try { TcpClient.Connect(); } catch (Exception e) { Synapse.Api.Logger.Get.Error($"Failed to first connect to Syncord Bot ({_ipPortEndpoint}){Environment.NewLine}{e}"); return; } if (SyncordPlugin.Config.AutoReconnect) { _reconnectWorker = new BackgroundWorker(); _reconnectWorker.DoWork += OnDoWorkReconnectWorker; _reconnectWorker.RunWorkerCompleted += OnReconnectWorkerCompleted; _reconnectWorker.RunWorkerAsync(); } }
///////////////////////////////////// // Public ///////////////////////////////////// public bool Connect(string ipAddress = "127.0.0.1", int port = 7788) { try { client = new SimpleTcpClient(); //client.Delimiter = 10; //client.DelimiterDataReceived += (o, e) => { Console.WriteLine("Delimiter data received"); }; client.DelimiterDataReceived += DataReceived; //client.DataReceived += DataReceived; client.Connect(ipAddress, port); disconnectTimer.Start(); //pingServer.Start(); InvokeOutput("Client Connected."); if (!hasConnectedBefore) { hasConnectedBefore = true; Application.Current.MainWindow.Closed += Program_Exit; } OnConnected?.Invoke(); return(true); } catch (Exception ex) { Console.WriteLine("Warning#001: " + ex.Message); InvokeOutput("Client Not Connected."); return(false); } }
public void Dispose() { _socket.Disconnect(); _socket.Close(); _socket = null; if (_sender != null) { _sender.Disconnect(); _sender.Dispose(); _sender = null; } if (_receiver != null) { if (_receiver.IsStarted) { _receiver.Stop(); } _receiver = null; } }
internal static void Connect() { Client = new SimpleTcpClient(); Client.DataReceived += ClientOnDataReceived; Client.DelimiterDataReceived += ClientOnDelimiterDataReceived; //connection lost, let's try to reconnect while (Client.TcpClient == null || !Client.TcpClient.Connected) { try { Client.Connect(Settings.ServerIP, Settings.Port); var regInfo = new ClientRegistrationInfo { ClientId = ClientId }; var json = JsonConvert.SerializeObject(regInfo); Client.WriteLine(json); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } Console.WriteLine($"Error in reconnect: {ex.Message}\n{ex.StackTrace}\n"); } Thread.Sleep(100); } }
public ClientTcp() { client = new SimpleTcpClient(1024, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 11000)); client.OnException += Client_OnException; client.OnReceivedMessage += Client_OnReceivedMessage; client.Start(); }
private async Task <List <MachineOnlineModel> > GetMachineStatus(List <MachineOnlineModel> listMC) { List <MachineOnlineModel> list = new List <MachineOnlineModel>(); return(await Task.Factory.StartNew(() => { foreach (var mc in listMC) { MachineOnlineModel _mc = new MachineOnlineModel(); try { using (SimpleTcpClient client = new SimpleTcpClient()) { client.Connect(mc.IP, 1000); _mc.IP = mc.IP; _mc.isOnline = true; } } catch (Exception) { _mc.IP = mc.IP; _mc.isOnline = false; } list.Add(_mc); } return list; })); }
public bool BeginCommunication(SimpleTcpClient client) { this.simpleTcpClient = client; this.simpleTcpClient.DataReceived += this.onPackageReceived; this.simpleTcpClient.DelimiterDataReceived += this.onPackageReceived; return(this.StartCommunication()); }
public async Task Start_StartServerAndConnectWithOneClient_Successful() { var ipAddress = "127.0.0.1"; var port = 8000; var expectedClientConnectedCount = 1; var clientConnectedCount = 0; void ClientConnected(object?sender, ConnectionEventArgs e) { clientConnectedCount++; } using var simpleTcpServer = new SimpleTcpServer($"{ipAddress}:{port}"); simpleTcpServer.Start(); simpleTcpServer.Events.ClientConnected += ClientConnected; using var simpleTcpClient = new SimpleTcpClient($"{ipAddress}:{port}"); simpleTcpClient.Connect(); simpleTcpClient.Send("test"); simpleTcpClient.Disconnect(); await Task.Delay(10); simpleTcpServer.Events.ClientConnected -= ClientConnected; simpleTcpServer.Stop(); Assert.AreEqual(expectedClientConnectedCount, clientConnectedCount); }
public void Start(int port, string ip) { this.Client = new SimpleTcpClient(); this.Client.DataReceived += this.Client_DataReceived; this.Client.Connect(ip, port); }
public bool BeginCommunication(SimpleTcpClient client) { simpleTcpClient = client; simpleTcpClient.DataReceived += OnPackageReceived; simpleTcpClient.DelimiterDataReceived += OnPackageReceived; return(StartCommunication()); }
public void TryToConnect() { try { client = new SimpleTcpClient(ip, 23190); /** * Register event handlers */ client.Events.Connected += Connected; client.Events.Disconnected += Disconnected; client.Events.DataReceived += DataReceived; client.Connect(); } catch (Exception e) { DialogResult dr = MessageBox.Show( e.Message, "Nastala chyba při pokusu o připojení", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error ); if (dr == DialogResult.Retry) { TryToConnect(); } } }
public async Task <bool> Conenct(string ip) { if (sock != null) { sock.Events.Connected -= Sock_Connected; sock.Events.DataReceived -= Sock_DataReceived; sock.Events.Disconnected -= Sock_Disconnected; sock.Dispose(); sock = null; } sock = new SimpleTcpClient(_ip, 7171, false, null, null); sock.Events.Connected += Sock_Connected; sock.Events.DataReceived += Sock_DataReceived; sock.Events.Disconnected += Sock_Disconnected; try { cancelTock = new CancellationTokenSource(); if (ip == "0.0.0.0") { return(false); } await Task.Run(() => sock.Connect()); ParsRun(); return(true); } catch { sock.Dispose(); sock = null; Debug.WriteLine($"{ip}:7171 Client 소켓연결 실패."); return(false); } }
public TCPClint() { Console.WriteLine("welcome to clint"); clint = new SimpleTcpClient(); clint.StringEncoder = Encoding.UTF8; clint.DelimiterDataReceived += Clint_DelimiterDataReceived; }
public ViewRekamMedis(string no_rm) { InitializeComponent(); conn = DBConnection.dbConnection(); cmd = new DBCommand(conn); try { //sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //sck2 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ////sck3 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //sck.Connect(Properties.Settings.Default.ScoketServerApotik, Properties.Settings.Default.SockertPortApotik); //sck2.Connect(Properties.Settings.Default.SocketServerAntri, Properties.Settings.Default.SocketPortAntri); ////sck3.Connect(Properties.Settings.Default.SocketPApotik, Properties.Settings.Default.SocketPortPApotik); //clientApotik = new SimpleTcpClient(); //clientApotik.Connect(Properties.Settings.Default.ScoketServerApotik, Properties.Settings.Default.SockertPortApotik); clientPoli = new SimpleTcpClient(); clientPoli.Connect(Settings.Default.SocketServerAntri, Settings.Default.SocketPortAntri); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.no_rm = no_rm; DisplayDataPasien(no_rm); }
public TcpComm(int controlpadId, string ip, int port, TcpRecvDelegate tcpRecv) { this.ControlPadId = controlpadId; this.IP = ip; this.Port = port; this.TcpRecv = tcpRecv; SimpleTcp = new SimpleTcpClient(); ControlPadState = new ControlPadState[5]; try { SimpleTcp.Connect(ip, port); SimpleTcp.DataReceived += (sender, msg) => { Decode(msg.Data); }; } catch (Exception) { IsConnection = false; Task.Run(() => { checkState(); }); } }
static void Main(string[] args) { if (args.Length < 2) { ShowHelp(); } // No real checks, sends the command to the server blindly. // Server will expect P1-P8, END try { var serverPort = args[0]; var command = args[1]; var server = serverPort.Split(':')[0]; var port = int.Parse(serverPort.Split(':')[1]); var client = new SimpleTcpClient().Connect(server, port); client.WriteLine(command); client.Disconnect(); } catch (Exception ex) { Console.WriteLine(ex); } }
private void Client2_Load(object sender, EventArgs e) { client = new SimpleTcpClient(txtIP.Text); client.Events.Connected += Events_Connected; client.Events.DataReceived += Events_DataReceived; client.Events.Disconnected += Events_Disconnected; }
public void SimpleCommTest() { SimpleTcpServer server = new SimpleTcpServer().Start(8910); SimpleTcpClient client = new SimpleTcpClient().Connect(server.GetListeningIPs().FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString(), 8910); server.DelimiterDataReceived += (sender, msg) => { _serverRx.Add(msg.MessageString); string serverReply = Guid.NewGuid().ToString(); msg.ReplyLine(serverReply); _serverTx.Add(serverReply); }; client.DelimiterDataReceived += (sender, msg) => { _clientRx.Add(msg.MessageString); }; System.Threading.Thread.Sleep(1000); if (server.ConnectedClientsCount == 0) { Assert.Fail("Server did not register connected client"); } for (int i = 0; i < 10; i++) { string clientTxMsg = Guid.NewGuid().ToString(); _clientTx.Add(clientTxMsg); client.WriteLine(clientTxMsg); System.Threading.Thread.Sleep(100); } System.Threading.Thread.Sleep(1000); for (int i = 0; i < 10; i++) { if (_clientTx[i] != _serverRx[i]) { Assert.Fail("Client TX " + i.ToString() + " did not match server RX " + i.ToString()); } if (_serverTx[i] != _clientRx[i]) { Assert.Fail("Client RX " + i.ToString() + " did not match server TX " + i.ToString()); } } var reply = client.WriteLineAndGetReply("TEST", TimeSpan.FromSeconds(1)); if (reply == null) { Assert.Fail("WriteLineAndGetReply returned null"); } Assert.IsTrue(true); }