0
我可以在StreamReader套接字C#上收到一個int嗎?我可以在StreamReader套接字C#上收到一個int嗎?
我開發了一個java數據應用程序客戶端通過套接字發送int到C#中的應用程序服務器,但我不知道我怎麼能收到一個int。因爲如果我把int mensagem = sr.ReadLine()不工作!
服務器應用程序的C#中的代碼:
//Some code not include.
public void Server()
{
Socket soc = listener.AcceptSocket();
//Informa uma conecção
//MessageBox.Show("Conectado: " + soc.RemoteEndPoint);
try
{
Stream s = new NetworkStream(soc);
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);
sw.AutoFlush = true; // enable automatic flushing
while (true)
{
string mensagem = sr.ReadLine(); //if i put int message not work why?
comando(mensagem);
}
//s.Close();
}
catch (Exception e)
{
MessageBox.Show("Erro!" + e.Message);
}
//MessageBox.Show("Disconectado: " + soc.RemoteEndPoint);
//soc.Close();
} //Fim Função Server
題外話,但你應該使用'與是一次性的('Stream','StreamReader','StreamWriter') –