title: C# Sockets (TCP & UDP)
body: <p>I'll cut to the point, I've been stuck on this for a few hours now. Tons of Google and tons of research but not straight answer as of yet.</p>
  
  <p>I have a client and a server coded for TCP which functions perfectly fine, however, I want the client to also be able to use UDP with the server for none-important packets such as player location.</p>
  
  <p>As of right now, this is my connect code for connected clients.</p>
  
  <pre><code>public void ConnectToServer(){
      tcp_client = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
      tcp_client.Connect(server_ip, server_port);
      tcp_stream = new NetworkStream(this.tcp_client);
  
      this.udp_client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
      this.udp_client.BeginConnect(IPAddress.Parse(server_ip), server_port,new AsyncCallback(udp_connected), null);
  }
  </code></pre>
  
  <p>Now the client isn't what I've had issues with for when I use <code>udp.Send(byteArray)</code> it appears to be sending as it's not throwing any exceptions but the server itself isn't responding to any data received.</p>
  
  <p><em>Please Note this is NOT 100% copy/pasted code. Alter to show just what's being an issue.</em></p>
  
  <pre><code>private Socket c;
  private UdpClient udp;
  private isRunning = true;
  
  public Client(Socket c){
      // This was accepted from TcpListener on Main Server Thread.
      this.c = c;
      this.networkStream = new NetworkStream(this.c);
  
      udp = new UdpClient();
      udp.Connect((IPEndPoint)c.RemoteEndPoint);
  
      // Then starts 2 thread for listening, 1 for TCP and 1 for UDP.
  }
  
  private void handleUDPTraffic(){
      IPEndPoint groupEP = (IPEndPoint)c.RemoteEndPoint;
      while (isRunning){
          try{
              byte[] udp_received = udp.Receive(ref groupEP);
              Console.WriteLine("Received UDP Packet Data: " + udp_received.Length);
          }catch{
              log.ERROR("UDP", "Couldn't Receive Data...");
          }
      }
  }
  </code></pre>