title: UDP server and UDP client
body: <p>I have problem. Why my client cannot recieve data from server? Server is recieving data from client without problems. Is it because my client is not connected on my server client. Have someone any idea? And sorry for my English, I am from Czech Republic. :)</p>
  
  <p>This is my UDP client:</p>
  
  <pre><code>    UdpClient client;
      public IPAddress serverIP = IPAddress.Parse("127.0.0.1");
      public Form1()
      {
          InitializeComponent();
          client = new UdpClient();
      }
  
      public void SendData()
      {
          client.Connect(serverIP, 3000);
          byte[] data = Encoding.ASCII.GetBytes("Hi, I'm new client.");
          client.Send(data, data.Length);
          DoListening();
      }
      public void DoListening()
      {
          IPEndPoint adress = new IPEndPoint(serverIP, 3000);
          byte[] receivedbytes = client.Receive(ref adress);
          string recieved = Encoding.ASCII.GetString(receivedbytes);
  
          MessageBox.Show("Recieved: " + recieved);
      }
      private void button1_Click(object sender, EventArgs e)
      {
          SendData();
      }
  </code></pre>
  
  <p>This is my UDP server:</p>
  
  <pre><code>    public Form1()
      {
          InitializeComponent();
          Thread listening = new Thread(new ThreadStart(DoListening));
          listening.Start();
      }
      public void ClientThread(Object adress)
      {
          IPEndPoint ip = adress as IPEndPoint;
          UdpClient client = new UdpClient();
          client.Connect(ip);
          byte[] data = Encoding.ASCII.GetBytes("No nazdar");
          client.Send(data, data.Length);
          MessageBox.Show("Sending data..");
      }
      public void DoListening()
      {
          while (true)
          {
              UdpClient client = null;
              client = new UdpClient(3000);
              IPEndPoint host = new IPEndPoint(IPAddress.Any, 0);
              MessageBox.Show("Listening");
              byte[] receivedbytes = client.Receive(ref host);
              string recieved = Encoding.ASCII.GetString(receivedbytes);
              MessageBox.Show("Client " + host.Address.ToString() + " conected. Message: " + recieved);
              new Thread(new ParameterizedThreadStart(ClientThread)).Start(host);
              Console.WriteLine("Doslo k vyjimce z duvodu : {0}", ex.SocketErrorCode);
          }
      }
  </code></pre>