title: C# Chat Program Lidgren
body: <p>I wrote the following program that is suppose to start up, show the form and connect to the server and get an messages. However when I start it nothing happens?</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.Windows.Forms;
  using Lidgren.Network;
  using System.Threading;
  
  namespace WindowsGame2
  {
      public partial class Form1 : Form
      {
          private NetClient client;
          private NetBuffer buffer;
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Connect()
          {
              NetConfiguration config = new NetConfiguration("xesh");
              NetClient client = new NetClient(config);
  
              client.Connect("75.127.105.216", 14242);
  
              NetBuffer buffer = client.CreateBuffer();
          }
  
          private void ReceiveMessages()
          {
              Connect();
              bool keepGoing = true;
              while (keepGoing)
              {
                  NetMessageType type;
                  while (client.ReadMessage(buffer, out type))
                  {
                      switch (type)
                      {
                          case NetMessageType.DebugMessage:
                              Console.WriteLine(buffer.ReadString());
                              break;
  
                          case NetMessageType.StatusChanged:
                              Console.WriteLine("New status: " + client.Status + " Reason: " + buffer.ReadString());
                              break;
  
                          case NetMessageType.Data:
                              break;
                      }
                  }
              }
          }
  
          private void Update(string str)
          {
              ReceiveMessages();
              textBox1.AppendText(str + "\r\n");
          }
  
          private void textBox1_TextChanged(object sender, EventArgs e)
          {
  
          }
  
          static void Main(string[] args)
          {
              Form1 form = new Form1();
          }
      }
  }
  </code></pre>