1.java如何实现从远程ip和端口接收数,源码最好能够给出源码,源码连锁直销系统源码类似于tcp/ip网络调试助手。源码权限设计源码
java如何实现从远程ip和端口接收数,源码出货提示源码最好能够给出源码,源码早期游戏源码类似于tcp/ip网络调试助手。源码nacos源码教学
import java.net.*;
import java.io.*;
public class TestSocketClient {
public static void main(String[] args) {
try {
Socket socket = new Socket(".0.0.1",源码 );
System.out.println("请输入计算式:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s1 = br.readLine();
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream());
dos.writeUTF(s1);
dos.flush();
double s = dis.readDouble();
System.out.println("计算结果:" + s);
dis.close();
dos.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println("连接出错");
System.exit(-1);
}
}
}
服务器端:
import java.net.*;
import java.io.*;
public class TestSocketServer {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket();
Socket socket = ss.accept();
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = new DataInputStream(socket.getInputStream());
String s = null;
if ((s = dis.readUTF()) != null) {
System.out.println("接收到的算式:" + s);
double result = 0;
String[] sarr1 = s.split("[\\+\\-\\*\\/]");
double a = Double.parseDouble(sarr1[0].trim());
double b = Double.parseDouble(sarr1[1].trim());
String[] sarr2 = s.split("^(-?\\d+)(\\.\\d+)?");
char c = sarr2[1].trim().charAt(0);
switch (c) {
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
default:
break;
}
dos.writeDouble(result);
dos.flush();
}
dis.close();
dos.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
}
2024-11-30 00:172811人浏览
2024-11-30 00:102141人浏览
2024-11-29 23:321933人浏览
2024-11-29 22:552250人浏览
2024-11-29 22:24193人浏览
2024-11-29 22:14914人浏览
1.四六级报名浏览器有哪些?2.我想做一个网上报名系统,不知道怎么弄!3.什么浏览器可以报名四六级?4.艺考报名APP添巨堵 数十万艺术考生难报名的背后四六级报名浏览器有哪些? 报四六级最快的浏览
1.Python浪漫表白源码合集爱心、玫瑰花、照片墙)2.画爱心的python代码3.爱心的代码怎么打4.Python满屏飘爱心代码?5.爱心代码——李峋Python浪漫表白源码合集爱心、玫瑰花、照片