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

public class Client
{  
    private static NetworkStream ns;
    private static Socket socket;

    public static void Main(string[] args)
    {
        //Client liest Daten ein
        Console.WriteLine("Client");

        IPAddress ipadr = IPAddress.Parse("127.0.0.1");
        TcpListener tcpListener = new TcpListener(ipadr, 9000);
        tcpListener.Start();
        socket = tcpListener.AcceptSocket();

        if (socket.Connected)
        {
            ns = new NetworkStream(socket);
            byte[] readBytes = new byte[10];
            UnicodeEncoding ue = new UnicodeEncoding();

            AsyncCallback callback = new AsyncCallback(CallbackMethod);
            ns.BeginRead(readBytes, 0, 10, callback, null);

            string receive = ue.GetString(readBytes);

            Console.WriteLine(receive);
        }

        Console.ReadLine();
    }

    public static void CallbackMethod(IAsyncResult iar)
    {
        ns.EndRead(iar);
        ns.Close();
        socket.Close();
    }

}
