このコードを使用すると、空のバイト配列が受信者に送信されます。なぜ、ストリームには何も書き込まず、取得するだけです。それを防ぐために私は何ができますか?
public void Send()
{
TcpClient client = new TcpClient();
IPEndPoint serverEndPoint = new IPEndPoint( IPAddress.Parse( ip ), port );
client.Connect( serverEndPoint );
NetworkStream clientStream = client.GetStream();
clientStream.Close();
client.Close();
}
private TcpListener tcpListener;
private Thread listenThread;
public void Receiver()
{
this.tcpListener = new TcpListener( IPAddress.Any, port );
this.listenThread = new Thread( new ThreadStart( ListenForClients ) );
this.listenThread.Start();
}
private void ListenForClients()
{
this.tcpListener.Start();
while ( true )
{
//blocks until a client has connected to the server
TcpClient client = this.tcpListener.AcceptTcpClient();
Thread clientThread = new Thread( new ParameterizedThreadStart( HandleClientComm ));
clientThread.Start( client );
}
}
private void HandleClientComm( object client )
{
TcpClient tcpClient = (TcpClient)client;
NetworkStream clientStream = tcpClient.GetStream();
tcpClient.Close();
}