title: A Problem With The Module "SimpleTCP" When Making a Chat Application
body: <p>So I wanted to make a chat app in C#, I watched a video about it(<a href="https://www.youtube.com/watch?v=ve2LX1tOwIM" rel="nofollow noreferrer">https://www.youtube.com/watch?v=ve2LX1tOwIM</a>), I completely copied the code for now but when I run the server, Connect the client to the server and send a message from the client what happen is that it infinitely sends the message to both client and server. I am not sure why it does that since the code is exactly like shown in the video I watched. You can see this in my <a href="https://github.com/Noderdotbat/HyperChat-Server" rel="nofollow noreferrer">repository</a>.</p>
  
  <p>In case you want to see the code:
  Client: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using SimpleTCP;
  
  namespace Client
  {
      public partial class ClientForm : Form
      {
          SimpleTcpClient client;
  
          public ClientForm()
          {
              InitializeComponent();
          }
  
          private void ClientForm_Load(object sender, EventArgs e)
          {
              client = new SimpleTcpClient();
              client.StringEncoder = Encoding.UTF8;
              client.DataReceived += Client_DataReceived;
          }
  
          private void Client_DataReceived(Object sender, SimpleTCP.Message e)
          {
              txtStatus.Invoke((MethodInvoker)delegate ()
              {
                  txtStatus.Text += e.MessageString;
                  e.ReplyLine(String.Format("You: {0}", e.MessageString));
              });
          }
  
          private void SendMessageInput_Click(object sender, EventArgs e)
          {
              client.WriteLine(MessageInput.Text);
          }
  
          private void StartInput_Click(object sender, EventArgs e)
          {
              StartInput.Enabled = false;
              client.Connect(HostInput.Text, Convert.ToInt32(PortInput.Text));
          }
      }
  }
  </code></pre>
  
  <p>And that is the Server:</p>
  
  <pre><code>using System;
  using System.Net;
  using System.Text;
  using System.Windows.Forms;
  using SimpleTCP;
  
  namespace HyperChat
  {
      public partial class ServerForm : Form
      {
          SimpleTcpServer server;
  
          public ServerForm()
          {
              InitializeComponent();
          }
  
          private void ServerForm_Load(object sender, EventArgs e)
          {
              server = new SimpleTcpServer();
              server.Delimiter = 0x13;
              server.StringEncoder = Encoding.UTF8;
              server.DataReceived += Server_DataReceived;
          }
  
          private void Server_DataReceived(object sender, SimpleTCP.Message e)
          {
              txtStatus.Invoke((MethodInvoker)delegate ()
              {
                  txtStatus.Text += e.MessageString;
                  e.ReplyLine(String.Format("You: {0}", e.MessageString));
              });
          }
  
          private void StartButton_Click(object sender, EventArgs e)
          {
              txtStatus.Text += "Server Started...";
              IPAddress ip = IPAddress.Parse(hostInput.Text);
              server.Start(ip, Convert.ToInt32(portInput.Text));
              StartButton.Enabled = false;
          }
  
          private void StopButton_Click(object sender, EventArgs e)
          {
              if (server.IsStarted)
              {
                  server.Stop();
              }
          }
      }
  }
  </code></pre>
  
  <p>I would really appreciate getting help, I tried messing up with my code but it didn't really work, I do want to mention that in the video they said you need to connect to get the IP you want to connect using:</p>
  
  <pre><code>System.Net.IPAddress ip = new System.Net.IPAddress(long.Parse(txtHost.Text))
  </code></pre>
  
  <p>But it gives errors and what you really need to do is:</p>
  
  <pre><code>System.Net.IPAddress ip = System.Net.IPAddress.Parse(hostInput.Text);
  </code></pre>
  
  <p>What I expect to happen is the server to send the message like it should but for some reason it doesn't.
  I would really appreciate getting help with this. Thanks.</p>