बस मैं जावा में BufferedStreamReader
क्या लागू करने की कोशिश कर रहा हूं। मेरे पास एक सॉकेट स्ट्रीम खुली है और बस लाइन द्वारा लाइन-उन्मुख फैशन लाइन में इसे पढ़ना चाहती है।सी # - StreamReader.ReadLine ठीक से काम नहीं करता है!
मेरे पास निम्न सर्वर-कोड है।
while (continueProcess)
{
try
{
StreamReader reader = new StreamReader(Socket.GetStream(), Encoding.UTF8);
string command = reader.ReadLine();
if (command == null)
break;
OnClientExecute(command);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
और निम्न क्लाइंट-कोड:
TcpClient tcpClient = new TcpClient();
try
{
tcpClient.Connect("localhost", serverPort);
StreamWriter writer = new StreamWriter(tcpClient.GetStream(), Encoding.UTF8);
writer.AutoFlush = true;
writer.WriteLine("login>user,pass");
writer.WriteLine("print>param1,param2,param3");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
tcpClient.Close();
}
सर्वर केवल बहुत पहली पंक्ति पढ़ता (login>user,pass
) और फिर ReadLine
रिटर्न अशक्त!
इस लाइन उन्मुख पाठक को प्राप्त करने का सबसे आसान तरीका क्या है क्योंकि यह जावा के BufferedStreamReader
में है? :
है। अन्यथा आपको अप्रत्याशित समस्याएं मिल सकती हैं। बस उनके चारों ओर एक प्रयोग ब्लॉक डालें (जैसा कि (स्ट्रीमवाइटर लेखक = ...) {}) में उपयोग किया जा रहा है, और आप ठीक होंगे – configurator
यह नहीं कि यह प्रश्न के लिए प्रासंगिक था - बस एक सुझाव। – configurator
महान;) धन्यवाद – Aleyna