private void Connect_Click(object sender, EventArgs e)
 {
     ConnectBtn.Enabled = false;
     client.Connect(txtHost.Text, Convert.ToInt32(txtPort.Text));
     gettingid = true;
     client.WriteLine(txtUser.Text);
 }
        private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            //throw new NotImplementedException();
            Dispatcher.Invoke(() =>
            {
                try
                {
                    //Debug.WriteLine(sp.ReadLine().Replace("\r", ""));
                    //Debug.WriteLine(sp.ReadLine());
                    var a = sp.ReadLine().Replace("\r", "");
                    //Debug.WriteLine(Properties.Settings.Default.IsRemoteConnected);
                    if (!Settings.Default.IsRemoteConnected)
                    {
                        //int v = 0;
                        if (int.TryParse(a, out var v))
                        {
                            clientApotik.WriteLineAndGetReply(a, TimeSpan.FromSeconds(0));
                        }
                    }
                    else
                    {
                        if (int.TryParse(a, out var v))
                        {
                            clientApotik.WriteLine(a);
                        }

                        if (a == ">>|")
                        {
                            if (cmd.UpdateAntrian())
                            {
                                clientApotik.WriteLine("Update");
                            }
                        }

                        if (a == "|<<")
                        {
                            if (cmd.UpdateAntrianPrev())
                            {
                                clientApotik.WriteLine("Update");
                            }
                        }
                    }

                    //var a = sp.ReadLine().Replace("\r", "");
                    //if (a == "Update")
                    //{
                    //    if (cmd.UpdateAntrian())
                    //    {
                    //        //sck.Send(Encoding.ASCII.GetBytes("Update"));
                    //        clientApotik.WriteLine("Update");
                    //    }
                    //}
                }
                catch (Exception)
                {
                    //ignore
                }
            });
        }
Example #3
0
        // the function below is handed over to the client object
        // and acts as EventHandler,  see SimpleTcpClient.cs
        // The client object knows nothing about the txtStatus box,
        //

        private void btnSend_Click(object sender, EventArgs e)
        {
            //SimpleTCP.Message newmessage = Client.WriteLineAndGetReply(txtMessage.Text, TimeSpan.FromMilliseconds(100));

            current_command = (int)command.SEND_SIMPLE;
            Client.WriteLine(txtMessage.Text);
            // data is received via event handler Client_DataReceived_phase1/2
            // Client_DataReceived_phase1/2 will handle the reply
        }
Example #4
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     btnConnect.Enabled = false;
     btnStop.Enabled    = true;
     clientName         = textName.Text;
     textStatus.Text   += "Connected" + System.Environment.NewLine;
     client.Connect(textHost.Text, Convert.ToInt32(textPort.Text));
     client.WriteLine("Connected");
     client.WriteLine("#N#A#M#E# " + clientName + ":");
 }
Example #5
0
 public static void SendShutdownSignal()
 {
     if (Client != null)
     {
         try
         {
             Client.WriteLine(Server.ClientID.ToString() + "|shutdown|0");
         }
         catch { }
     }
 }
        private void join_button_Click(object sender, EventArgs e)
        {
            string password = "";

            currentChannel = dataGridView1.CurrentCell.RowIndex;
            DataGridViewCheckBoxCell chechbox = dataGridView1.Rows[currentChannel].Cells["Haslo"] as DataGridViewCheckBoxCell;

            if (Convert.ToBoolean(chechbox.Value))
            {
                password = Prompt.ShowDialog("Hasło wymagane", "Podaj hasło");
            }
            client.WriteLine(diffieHellman.EncryptMessage(login + ";CH;" + dataGridView1.CurrentCell.RowIndex + ";" + SHA.ChangeToSHA2_256(password)));
        }
        private void RegisterButton_Click(object sender, EventArgs e)
        {
            string login     = text_user.Text;
            string password  = text_password.Text;
            string password2 = TextRepeatPassword.Text;

            if (login.Length == 0 || password.Length == 0 || password2.Length == 0)
            {
                MessageBox.Show("Wszystkie pola są wymagane!");
            }
            else if (password != password2)
            {
                MessageBox.Show("Hasła się nie zgadzają!");
            }
            else if (CheckStrength(password) == false)
            {
                MessageBox.Show("Hasło za słabe. Musi składać się z 8 znaków oraz zawierać wielką literę i znak specjalny.");
            }
            else if (login.Length < 5)
            {
                MessageBox.Show("Login musi składać się z przynajmniej 5 znaków");
            }
            else
            {
                password = SHA.ChangeToSHA2_256(password);
                client.WriteLine(diffieHellman.EncryptMessage("REG;" + login + ";" + password));
            }
        }
Example #8
0
 // events
 private void WaitingRoom_Load(object sender, EventArgs e)
 {
     if (who == "client")
     {
         client.WriteLine(name);
     }
 }
Example #9
0
        public void PlaceAChess(int x, int y)
        {
            if (_isConnecting && _client != null)
            {
                // client send data
                _client.WriteLine("player:" + player_name + "," + x + "," + y);
            }
            if (_isHosting && _server != null)
            {
                // server send data
                _server.BroadcastLine("player:" + player_name + "," + x + "," + y);
            }
            Chess chess = _game.PlaceAChess(x, y);

            if (chess != null)
            {
                chess.Name = "chess";
                this.Controls.Add(chess);
                _audio.Play();
            }
            if (_game.IsGameOver)
            {
                if (!_game.IsBlack)
                {
                    MessageBox.Show("Black wins");
                }
                else
                {
                    MessageBox.Show("White wins");
                }
                Reset();
            }
        }
Example #10
0
        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);
            }
        }
Example #11
0
        private void GetClient(object sender, SimpleTCP.Message e)
        {
            string recieved = Regex.Replace(e.MessageString, @"\u0013", String.Empty);

            if (firstTime)
            {
                string[] coords = recieved.Split(',');

                Point p = new Point(int.Parse(coords[0]), int.Parse(coords[1]));

                f = new Food(Color.Black, Color.White, g, s, p);

                firstTime = false;
            }

            if (true)
            {
                string[]     ps = recieved.Split('|');
                List <Point> ls = new List <Point>();
                foreach (string p in ps)
                {
                    string[] coords = p.Split(',');
                    ls.Add(new Point(int.Parse(coords[0]), int.Parse(coords[1])));
                }
                s1.Position = ls;
                client.WriteLine(Compress(s.Position));
            }

            sketch.Invalidate();
        }
Example #12
0
 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);
     }
 }
Example #13
0
        private void btnSelesai_Click(object sender, RoutedEventArgs e)
        {
            var total = 0;

            foreach (ModelDetailResep dr in dtgDetailResep.ItemsSource)
            {
                total += dr.sub_total;
            }

            //MessageBox.Show(total.ToString());
            if (cmd.CreateTransactionResep(Settings.Default.KodeApoteker,
                                           txtKodeResep.Text, total))
            {
                if (cmd.UpdateStatusAntrianApotik(kode_resep))
                {
                    try
                    {
                        clientApotik.WriteLine("Update");
                    }
                    catch (Exception)
                    {
                    }

                    ClearData();
                }
            }
        }
        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;
        }
Example #15
0
        public void SimpleCommTest()
        {
            SimpleTcpServer server = new SimpleTcpServer().Start(8910);
            SimpleTcpClient client = new SimpleTcpClient(new SimpleTcpParam {
                Name = "Alex"
            }).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);
        }
Example #16
0
        public void Join(String Ip, int port)
        {
            IPAddress.TryParse(Ip, out address);
            try
            {
                client.Connect(Ip, 7000);

                client.WriteLine(logedUser);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());


                this.Dispose();
            }
        }
Example #17
0
        private void exit_Click(object sender, EventArgs e)
        {
            client.WriteLine(diffieHellman.EncryptMessage("EXIT;"));
            Server_IP ser = new Server_IP();

            Hide();
            ser.Show();
        }
Example #18
0
 private void sendMessage(String message)
 {
     //Send the message to the server.
     try {
         addLog("Sending message: " + message);
         client.WriteLine(message);
     } catch (Exception ex) {
         addLog("Error sending message: " + ex);
     }
 }
Example #19
0
 public static void SendMessage(string message)
 {
     try
     {
         client.WriteLine(message + '\n');
     }
     catch
     {
         MessageBox.Show("与服务器通讯出错,请重试");
     }
 }
Example #20
0
        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);
        }
Example #21
0
        private void LoginWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (client.TcpClient.Connected)
            {
                dynamic disconnectJson = new JObject();

                disconnectJson.command = "DISCONNECT";

                client.WriteLine(disconnectJson.ToString(Formatting.None));

                client.Disconnect();
            }
        }
Example #22
0
        private void SetProgram(string program)
        {
            engraver.WriteLine($"GA,{program}\r");

            if (program == "0009")
            {
                lblXT2.Visible = false;
                lblXT3.Visible = false;
                lblXT4.Visible = false;
                lblXT5.Visible = false;
                lblXT6.Visible = false;

                txtXT2.Visible = false;
                txtXT3.Visible = false;
                txtXT4.Visible = false;
                txtXT5.Visible = false;
                txtXT6.Visible = false;

                lblCurrent2.Visible = false;
                lblCurrent3.Visible = false;
                lblCurrent4.Visible = false;
                lblCurrent5.Visible = false;
                lblCurrent6.Visible = false;

                txtXT1.Clear();
            }
            else if (program == "0010")
            {
                lblXT2.Visible = true;
                lblXT3.Visible = true;
                lblXT4.Visible = true;
                lblXT5.Visible = true;
                lblXT6.Visible = true;

                txtXT2.Visible = true;
                txtXT3.Visible = true;
                txtXT4.Visible = true;
                txtXT5.Visible = true;
                txtXT6.Visible = true;

                lblCurrent2.Visible = true;
                lblCurrent3.Visible = true;
                lblCurrent4.Visible = true;
                lblCurrent5.Visible = true;
                lblCurrent6.Visible = true;

                txtXT1.Clear();
                txtXT2.Clear();
                txtXT3.Clear();
                txtXT4.Clear();
                txtXT5.Clear();
                txtXT6.Clear();
            }
            else
            {
                numLOC8.Value = 1;
                return;
            }
        }
Example #23
0
    public void create()
    {
        //port 8910
        cli           = new SimpleTcpClient().Connect("192.168.137.111", 8910);
        cli.Delimiter = 0x13;
        cli.WriteLine("knight");



        cli.DelimiterDataReceived += (sender, msg) =>
        {
            String[] param = msg.MessageString.Split(';');

            int id = Int32.Parse(param[1]);
            switch (param[0])
            {
            case "auth":
                myId = id;
                break;

            case "s":

                partyStarted = true;



                if (param[2] == "Mage")
                {
                    listPlayer.Add(new Mage(id));
                }
                if (param[2] == "Knight")
                {
                    listPlayer.Add(new Knight(id));
                }
                if (param[2] == "Archer")
                {
                    listPlayer.Add(new Archer(id));
                }

                break;

            case "c":
                if (id != myId)
                {
                    listPlayer[id].setPos(float.Parse(param[2]), float.Parse(param[3]), float.Parse(param[4]));
                }

                break;
            }
        };
    }
Example #24
0
    IEnumerator SendData()
    {
        while (true && partyStarted)
        {
            print(listPlayer.Count);

            try
            {
                cli.WriteLine("c;" + myId + ";" + this.transform.position.x + ";" + this.transform.position.y + ";" + this.transform.position.z);

                ////Moves Forward and back along z axis                           //Up/Down
                //listPlayer[myId].setPos(Vector3.forward * Time.deltaTime * Input.GetAxis("Vertical") * moveSpeed);
                ////Moves Left and right along x Axis                               //Left/Right
                //listPlayer[myId].setPos(Vector3.right * Time.deltaTime * Input.GetAxis("Horizontal") * moveSpeed);
                //print("J'envoie mes coord");
                //cli.WriteLine("c;" + myId + ";" + listPlayer[myId].getPos().x + ";" + listPlayer[myId].getPos().y + ";" + listPlayer[myId].getPos().z);
            }
            catch (Exception e)
            {
            }
            yield return(new WaitForSeconds(0.1f));
        }
    }
        private void btnsend_Click(object sender, EventArgs e)
        {
            /*try
             * {
             *  if(serialPort1.IsOpen)
             *  {
             *      serialPort1.WriteLine(txtMessage.Text + Environment.NewLine);
             *      txtMessage.Clear();
             *  }
             *
             * }
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
            /*NetworkStream serverStream = tcpclient.GetStream();
             * MessageBox.Show("1");
             * byte[] outStream = System.Text.Encoding.ASCII.GetBytes(txtMessage.Text + "$");
             * MessageBox.Show("2");
             * serverStream.Write(outStream, 0, outStream.Length);
             * MessageBox.Show("3");
             * serverStream.Flush();
             * MessageBox.Show("4");
             */

            client.WriteLine("WX,ProgramNo=" + txtMessage.Text);

            //txtMessage.Text = "";
            //txtMessage.Focus();

            /*byte[] inStream = new byte[10025];
             * serverStream.Read(inStream, 0, (int)tcpclient.ReceiveBufferSize);
             * string returndata = System.Text.Encoding.ASCII.GetString(inStream);
             * msg(returndata);
             * txtMessage.Text = "";
             * txtMessage.Focus();*/
        }
Example #26
0
 public void StopNode(StopNodeRequest req)
 {
     try
     {
         if (Client.TcpClient == null || !Client.TcpClient.Connected)
         {
             Client.Connect(_ip, _port);
         }
     }
     catch
     {
         // ignored
         return;
     }
     Client.TcpClient.ReceiveBufferSize = Int32.MaxValue;
     Client.WriteLine(JsonConvert.SerializeObject(req));
 }
Example #27
0
        public void Send(int command, object data = null, Action <object> cb = null)
        {
            int packetID = SaveCallback(cb);
            var packet   = PackJson(command, packetID, data);

            try
            {
                client.WriteLine(packet);

                InvokeOutput($"Packet Send: {packet}");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Warning#002: " + ex.Message);
                InvokeOutput($"Packet Not Send: {packet}");
            }
        }
Example #28
0
 public void Send(string msg, bool GetReply)
 {
     if (IsConnected())
     {
         try
         {
             if (GetReply)
             {
                 try
                 {
                     Client.WriteLineAndGetReply(msg, TimeSpan.FromSeconds(3));
                 }
                 catch (System.IO.IOException)
                 {
                     ColoredConsole.ColoredWriteLine("/// Connection to the server was lost! ///", ConsoleColor.Red);
                     Disconnect();
                 }
             }
             else
             {
                 try
                 {
                     Client.WriteLine(msg);
                 }
                 catch (System.IO.IOException)
                 {
                     ColoredConsole.ColoredWriteLine("/// Connection to the server was lost! ///", ConsoleColor.Red);
                     Disconnect();
                 }
             }
         }
         catch (InvalidOperationException)
         {
             ColoredConsole.ColoredWriteLine("/// First connect to a server ///", ConsoleColor.Yellow);
         }
         catch (NullReferenceException)
         {
             ColoredConsole.ColoredWriteLine("/// First connect to a server ///", ConsoleColor.Yellow);
         }
     }
     else
     {
         ColoredConsole.ColoredWriteLine("/// First connect to a server ///", ConsoleColor.Yellow);
     }
 }
Example #29
0
 private void connect_button_Click(object sender, EventArgs e)
 {
     try
     {
         if (CheckIP(server_ip_text.Text) == true)
         {
             SetupTCPClient(server_ip_text.Text);
             Console.WriteLine(Convert.ToBase64String(diffieHellman.clientPublicKey));
             client.WriteLine("DHCK;" + Convert.ToBase64String(diffieHellman.clientPublicKey));
         }
         else
         {
             MessageBox.Show("To nie jest poprawny adres IP!");
         }
     }
     catch
     {
         MessageBox.Show("Nie można połączyć się z serwerem!");
     }
 }
Example #30
0
        private void button1_Click(object sender, EventArgs e)
        {
            var thread = Convert.ToInt32(this.Threads.Text);

            for (int i = 0; i < thread; i++)
            {
                new Thread(() =>
                {
                    this.Mess("Init thread " + i);
                    var client           = new SimpleTcpClient().Connect(this.ip.Text, Convert.ToInt32(this.Port.Text));
                    client.DataReceived += (object s, SimpleTCP.Message m) =>
                    {
                        this.Mess(m.MessageString);
                    };
                    while (true)
                    {
                        client.WriteLine("hacked");
                    }
                }).Start();
            }
        }
Example #31
0
        private void ProcessHandheldPortMessage(object sender, SerialDataReceivedEventArgs e)
        {
            string strReceive = COMHandheld.ReadExisting();

            if (!strReceive.Contains("\r"))
            {
                CodeSumString += strReceive;
            }
            else
            {
                CodeSumString += strReceive;
                if (true)
                {
                    CodeSumString = CodeSumString.Replace("\r", "");
                    ReaderTCPClient.WriteLine($"Trigger,{CodeSumString},");
                    formMainDisplay.SetDataCode1(CodeSumString);
                    string serverRplString = "";
                    try
                    {
                        serverRplString = ReaderTCPClient.WriteLineAndGetReply($"Trigger,{CodeSumString},", new TimeSpan(0, 0, 5)).MessageString;
                    }
                    catch
                    {
                        serverRplString = "ERRTimeout, ERRTimeout, ERRTimeout";
                    }
                    formMainDisplay.SetDataCode2(serverRplString.Trim());
                    if (!serverRplString.Contains("ERR"))
                    {
                        formMainDisplay.SetOKLamp();
                    }
                    else
                    {
                        formMainDisplay.SetNGLamp();
                    }
                    CodeSumString = "";
                }
            }
        }