高手请进,求教
帮我看看我这个代码到底错在那里了
import java.io.*;
import java.net.*;
class client
{
public static void main(String[]args)throws Exception
{
Socket client=new Socket(InetAddress.getLocalHost(),52013);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bwin=new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader brin=new BufferedReader(new InputStreamReader(client.getInputStream()));
String str=null;
while((str=br.readLine())!=null)
{
if("over".equals(str))
break;
bwin.write(str);
bwin.newLine();
bwin.flush();
String str1=brin.readLine();
System.out.println(str1);
}
br.close();
client.close();
}
}
class server
{
public static void main(String[]args)throws Exception
{
ServerSocket server=new ServerSocket(52013);
Socket client=server.accept();
BufferedWriter bwin=new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
BufferedReader brin=new BufferedReader(new InputStreamReader(client.getInputStream()));
String str=null;
while((str=brin.readLine())!=null);
{
System.out.println(str);
bwin.write(str);
bwin.newLine();
bwin.flush();
}
client.close();
server.close();
}
}
------解决方案--------------------把server 端:
while((str=brin.readLine())!=null);
去掉后边分号!这样,服务器端接收到信息后还在这等待没,不执行下面的语句!改成:
while((str=brin.readLine())!=null)
------解决方案--------------------
while((str=brin.readLine())!=null)
;,楼上正解