使用网络stream.write时出错

时间:2013-05-24 23:24:11

标签: c# java sockets tcp bufferedreader

首先是我服务器代码的一部分:

while (true)
            {
                try
                {
                    requestCount = requestCount + 1;
                    NetworkStream networkStream = clientSocket.GetStream();
 rCount = Convert.ToString(requestCount);
                        serverResponse = "Server to clinet(" + clNo + ") " + " are u there ?" + Environment.NewLine;
                        sendBytes = Encoding.ASCII.GetBytes(serverResponse);
                       networkStream.Write(sendBytes, 0, sendBytes.Length);
                       networkStream.Flush();
                        Console.WriteLine(" >> " + serverResponse);

                }
                catch (Exception ex)
                {

                    Console.WriteLine(" >> error :  " + ex.Message);
                }


            }

这是我在客户端的代码:

    String k= null; 

     try {

          BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
          k = br.readLine();          
          System.out.println(k);

      }
     catch (IOException f) {
System.out.println("error is :  "+f.getMessage());

    }     
    catch (Exception g) {

      JOptionPane.showMessageDialog(null,"Server is offline","Alert !",JOptionPane.WARNING_MESSAGE);

    }

这里的错误是我的程序进入了一个不完整的循环 并继续在服务器输出中说...“>>服务器到clinet(1)你在那里?”

此外,我的客户端应用程序在没有收到消息的情况下冻结..! 任何帮助? thx:)(顺便说一下,我的客户端是java和我的服务器在c#上)

0 个答案:

没有答案