title: C# sockets cannot sent data
body: <p>Hello guys this method sending file on client machine </p>
  
  <pre><code>        private void StartServer()
      {
          TcpListener lsn = new TcpListener(IPAddress.Any, 27015);
          Socket sck;
  
          try
          {
              while (true)
              {
                  lsn.Start();
                  sck = lsn.AcceptSocket();
                  byte[] b = new byte[100];
                  int k = sck.Receive(b);
                  string recived = "";
  
                  for (int i = 0; i &lt; k; i++)
                  {
                      recived = "" + recived + "" + Convert.ToChar(b[i]).ToString();
                  }
  
                  if (recived == "Version")
                  {
                      string _ipPort = sck.RemoteEndPoint.ToString();
  
                      var parts = _ipPort.Split(':');
                      _IPAddr = IPAddress.Parse(parts[0]);
                      _Port = Convert.ToInt32(parts[1]);
                      sck.Send(System.Text.Encoding.ASCII.GetBytes("1.1.0.0"));
                  }
  
                  k = sck.Receive(b);
                  recived = "";
  
                  for (int i = 0; i &lt; k; i++)
                  {
                      recived = "" + recived + "" + Convert.ToChar(b[i]).ToString();
                  }
  
                  if (recived == "Update")
                  {
                      fName = "Cannonball.mp3";
  
                      byte[] fileName = Encoding.UTF8.GetBytes(fName);
                      byte[] fileData = File.ReadAllBytes("D:\\Cannonball.mp3");
                      byte[] fileNameLen = BitConverter.GetBytes(fileName.Length);
  
                      clientData = new byte[4 + fileName.Length + fileData.Length];
  
                      fileNameLen.CopyTo(clientData, 0);
                      fileName.CopyTo(clientData, 4);
                      fileData.CopyTo(clientData, 4 + fileName.Length);
  
                      if (sck.Connected == true)
                      {
                          sck.Send(clientData);
                          sck.Close();
                      }
  
                  }
              }
          }
          catch (Exception e)
          {
              MessageBox.Show(e.Message.ToString());
          }
      }
  </code></pre>
  
  <p>When its goes to last if statment does not doing nothing. I wrote this code </p>
  
  <pre><code>Socket sck1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                          sck1.Connect(_IPAddr, _Port);
                          sck1.Send(clientData);
  </code></pre>
  
  <p>but visual studio gives error that cannot establish connection. 
  I tried 999 port which i knew was open <code>sck1.Connect(_IPAddr, 999);</code> and client recieved file.
  Does anyone know how i can send file that remote endpoint(sck.RemoteEndPoint) which server got ? </p>