C# Programmation Réseau: Ecrire des données à travers le réseaux

Author:
 
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;


class Program {
    static void Main(string[] args) {
        TcpClient client = new TcpClient();
        IPHostEntry host = Dns.GetHostByName("www.google.com");
        client.Connect(host.AddressList[0], 8000);

        NetworkStream clientStream = client.GetStream();

        string request = "LIST";
        byte[] requestBuffer = Encoding.ASCII.GetBytes(request);
        clientStream.Write(requestBuffer, 0, requestBuffer.Length);

        byte[] responseBuffer = new byte[256];
        MemoryStream memStream = new MemoryStream();
        int bytesRead = 0;
        do {
            bytesRead = clientStream.Read(responseBuffer, 0, 256);
            memStream.Write(responseBuffer, 0, bytesRead);
        } while (bytesRead > 0);



    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *