主题:请谁帮我看一下这个程序!
import java.io.*;
import java.net.*;
public class TServer{
public static void main(String[] args) {
try{
ServerSocket ss=new ServerSocket(4700);
Socket s=ss.accept();
BufferedReader sysIn=new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer=new PrintWriter(s.getOutputStream());
BufferedReader reader=new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println("client:"+reader.readLine());
String line=sysIn.readLine();
while(!line.equals("goodbye")){
writer.print(line);
writer.flush();
System.out.println("server:"+line);
System.out.println("client:"+reader.readLine());
line=sysIn.readLine();
}
reader.close();
writer.close();
ss.close();
s.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
---------------------------------------------------------
-------------------------------------------------------------------
import java.io.*;
import java.net.*;
public class TClient {
public static void main(String[] args) {
try{
Socket s=new Socket("127.0.0.1",4700);
BufferedReader sysIn=new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer=new PrintWriter(s.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line=sysIn.readLine();
while(!line.equals("goodbye")){
writer.println(line);
writer.flush();
System.out.println("client:"+line);
System.out.println("server:"+reader.readLine());
line=sysIn.readLine();
}
writer.close();
reader.close();
s.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
----------------------------------------------
---------------------------------------------------------
是一个点对点程序。程序的功能是在自己电脑上开两个MSDOS窗口,两一个窗口进行对话。
出现的问题是:当两个窗口各自输入一句话后就出现阻塞了,得强行退出。
本人基础不行,实在看不出是哪里出现了问题。还希望谁能帮助一下!谢谢!
import java.net.*;
public class TServer{
public static void main(String[] args) {
try{
ServerSocket ss=new ServerSocket(4700);
Socket s=ss.accept();
BufferedReader sysIn=new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer=new PrintWriter(s.getOutputStream());
BufferedReader reader=new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println("client:"+reader.readLine());
String line=sysIn.readLine();
while(!line.equals("goodbye")){
writer.print(line);
writer.flush();
System.out.println("server:"+line);
System.out.println("client:"+reader.readLine());
line=sysIn.readLine();
}
reader.close();
writer.close();
ss.close();
s.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
---------------------------------------------------------
-------------------------------------------------------------------
import java.io.*;
import java.net.*;
public class TClient {
public static void main(String[] args) {
try{
Socket s=new Socket("127.0.0.1",4700);
BufferedReader sysIn=new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer=new PrintWriter(s.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
String line=sysIn.readLine();
while(!line.equals("goodbye")){
writer.println(line);
writer.flush();
System.out.println("client:"+line);
System.out.println("server:"+reader.readLine());
line=sysIn.readLine();
}
writer.close();
reader.close();
s.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
----------------------------------------------
---------------------------------------------------------
是一个点对点程序。程序的功能是在自己电脑上开两个MSDOS窗口,两一个窗口进行对话。
出现的问题是:当两个窗口各自输入一句话后就出现阻塞了,得强行退出。
本人基础不行,实在看不出是哪里出现了问题。还希望谁能帮助一下!谢谢!