请求朋友原谅的语句,Html文档若想请求到服务器端的消息,服务器端必须要有echo语句吗
答案:1 悬赏:0 手机版
解决时间 2021-08-15 21:45
- 提问者网友:書生途
- 2021-08-15 01:35
请求朋友原谅的语句,Html文档若想请求到服务器端的消息,服务器端必须要有echo语句吗
最佳答案
- 五星知识达人网友:詩光轨車
- 2021-08-15 02:33
java socket客户端向服务器端发送消息,可以使用socket类,实例如下:
mport java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String args[]) {
try {
Socket connection =new Socket(127.0.0.1, 5050);
BufferedReader input = new BufferedReader(new InputStreamReader(
connection.getInputStream()));PrintWriter out = new PrintWriter(connection.getOutputStream(),true );
String info;
info = input.readLine();
System.out.println(info);
boolean done = false;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String sInput;//out.println(BYE);
while (!done) {
info = input.readLine();
System.out.println(info);}
connection.close();
}
catch (SecurityException e) {
System.out.println(SecurityException when connecting Server!);
}
catch (IOException e) {
System.out.println(IOException when connecting Server!);
}
}
}
mport java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String args[]) {
try {
Socket connection =new Socket(127.0.0.1, 5050);
BufferedReader input = new BufferedReader(new InputStreamReader(
connection.getInputStream()));PrintWriter out = new PrintWriter(connection.getOutputStream(),true );
String info;
info = input.readLine();
System.out.println(info);
boolean done = false;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String sInput;//out.println(BYE);
while (!done) {
info = input.readLine();
System.out.println(info);}
connection.close();
}
catch (SecurityException e) {
System.out.println(SecurityException when connecting Server!);
}
catch (IOException e) {
System.out.println(IOException when connecting Server!);
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯