//server
import javaio;
import javanet;
public class MyServer {
public static void main(String[] args) throws IOException{
ServerSocket server=new ServerSocket(5678);
while (true) {
Socket client=serveraccept();
BufferedReader in=new BufferedReader(new InputStreamReader(clientgetInputStream()));
PrintWriter out=new PrintWriter(clientgetOutputStream());
//while(true){
String str=inreadLine();
Systemoutprintln(str);
outprintln("has receive");
outflush();
if("end"equals(str))
break;
//}
clientclose();
}
}
}
// client
import javanet;
import javaio;
public class Client{
static Socket server;
public static void main(String[] args)throws Exception{
server=new Socket(InetAddressgetLocalHost(),5678);
BufferedReader in=new BufferedReader(new InputStreamReader(servergetInputStream()));
PrintWriter out=new PrintWriter(servergetOutputStream());
BufferedReader wt=new BufferedReader(new InputStreamReader(Systemin));
while(true){
String str=wtreadLine();
outprintln(str);
outflush();
if(strequals("end")){
break;
}
Systemoutprintln(inreadLine());
}
serverclose();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)