Send data on a Socket

Last post 01-30-2003 11:22 by ctacke. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 01-30-2003 11:22

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 2,255

    Send data on a Socket

    Credit: Neil Cowburn


    int port = 99; // Port to connect to
    string filePath = @"\path\to\my\file.ext"; // The File to send
    IPAddress ip = IPAddress.Parse("127.0.0.1");
    IPEndPoint ipep = new IPEndPoint(ip, port); // IPEndPoint used
    Socket.Connect

    // Read in the file to a byte array
    FileStream fs = new FileStream(filePath, FileMode.Open);
    byte[] buffer = new byte[2048]; // Set the buffer length to 2KB
    fs.Read(buffer, 0, (int)fs.Length);


    // Set up the socket and connect
    Socket sck = new
    Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
    sck.Connect(ipep);

    // Send the byte array to the server
    sck.Send(buffer,SocketFlags.None);
Page 1 of 1 (1 items)