java 客户端和服务器!!急

java 客户端和服务器!!急,第1张

试试socket:
//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();
}
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10854748.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存