Ho inviato dati binari tra le applicazioni più volte su socket TCP ma mai prima di utilizzare le stringhe. Bumbed in un problema che intende farlo. Ecco cosa ho ottenuto:stringa di lettura/scrittura sul flusso di rete tcp
TcpClient tcpClient = new TcpClient("localhost", port);
//Connects fine
NetworkStream ns = tcpClient.GetStream();
StreamWriter sw = new StreamWriter(ns);
//The code moves on but nothing seems to be sent unless I do
//a sw.Close() after this line. That would however close the
//ns and prevent me from reading the response further down
sw.Write("hello");
//I am using a stream reader with ReadToEnd() on the tcpListener
//which never receives the string from this piece of code
//Since the above never actually send I get stuck here
string response = new StreamReader(ns).ReadToEnd();
sw.Close();
tcpClient.Close();
Come si invia la stringa senza chiudere il flusso di rete? ns.Flush() è ciò che cercherò davvero.
Una parola sul risciacquo. Dalla documentazione di NetworkStream ns.Flush() non fa nulla, e sw.Flush() è riservato per l'uso futuro ... quindi suppongo che il flushing in questo caso non faccia nulla. –
Questo non è corretto (se si tratta di un errore nel documento o meno). ns.Flush() è riservato per uso futuro ma non sw.Flush(). Se commento il sw.Flush(), fallisce. – BlueVoodoo