2个回答
展开全部
import java.net.*;
import java.io.*;
public class Server {
public static void main(String[] args) throws IOException {
String s = "";//用stringbuffer试试
String s1 = "";
ServerSocket server = new ServerSocket(60000);
System.out.println("可以开始通信");
try {
Socket socket = server.accept();
System.out.println(socket);
InputStream is = socket.getInputStream();
OutputStream out = socket.getOutputStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(is));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
s = bfr.readLine();
System.out.println("客户端对我说:" + s);//读取客户端信息并输出
if("bye".equals(s)) {
pw.println("bye");
pw.flush();
break;
}
s1 = br.readLine();
pw.println(s1);
pw.flush();
System.out.println("我对客户端说:" + s1);
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
server.close();
}
class Reader extends Thread {
public void run() {
while (true) {
}
}
}
}
import java.net.*;
import java.io.*;
public class Talk {
static InputStream is = null;
static OutputStream out;
static BufferedReader bfr;
static PrintWriter pw;
static BufferedReader pin;
public static void main(String[] args) throws IOException {
Socket socket = new Socket(InetAddress.getByName("localhost"), 60000);
System.out.println(socket);
try {
is = socket.getInputStream();
out = socket.getOutputStream();
bfr = new BufferedReader(new InputStreamReader(is));
pw = new PrintWriter(new OutputStreamWriter(out));
pin = new BufferedReader(new InputStreamReader(System.in));
new Controlaa().start();
while (true) {
String s1 = bfr.readLine();
System.out.println("服务器对我说:" + s1);//读取服务器端发送的信息
if (s1.equals("bye")) {
break;
}
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static class Controlaa extends Thread {
@Override
public void run() {
while (true) {
String s = "";
try {
s = pin.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("我对服务器说:" + s);
pw.println(s);
pw.flush();
}
}
}
}
简单搞了下,读取控制台输入和读取socket都是阻塞操作
import java.io.*;
public class Server {
public static void main(String[] args) throws IOException {
String s = "";//用stringbuffer试试
String s1 = "";
ServerSocket server = new ServerSocket(60000);
System.out.println("可以开始通信");
try {
Socket socket = server.accept();
System.out.println(socket);
InputStream is = socket.getInputStream();
OutputStream out = socket.getOutputStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(is));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
s = bfr.readLine();
System.out.println("客户端对我说:" + s);//读取客户端信息并输出
if("bye".equals(s)) {
pw.println("bye");
pw.flush();
break;
}
s1 = br.readLine();
pw.println(s1);
pw.flush();
System.out.println("我对客户端说:" + s1);
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
server.close();
}
class Reader extends Thread {
public void run() {
while (true) {
}
}
}
}
import java.net.*;
import java.io.*;
public class Talk {
static InputStream is = null;
static OutputStream out;
static BufferedReader bfr;
static PrintWriter pw;
static BufferedReader pin;
public static void main(String[] args) throws IOException {
Socket socket = new Socket(InetAddress.getByName("localhost"), 60000);
System.out.println(socket);
try {
is = socket.getInputStream();
out = socket.getOutputStream();
bfr = new BufferedReader(new InputStreamReader(is));
pw = new PrintWriter(new OutputStreamWriter(out));
pin = new BufferedReader(new InputStreamReader(System.in));
new Controlaa().start();
while (true) {
String s1 = bfr.readLine();
System.out.println("服务器对我说:" + s1);//读取服务器端发送的信息
if (s1.equals("bye")) {
break;
}
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static class Controlaa extends Thread {
@Override
public void run() {
while (true) {
String s = "";
try {
s = pin.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("我对服务器说:" + s);
pw.println(s);
pw.flush();
}
}
}
}
简单搞了下,读取控制台输入和读取socket都是阻塞操作
迪凯特科技(北京)有限公司
2023-08-23 广告
2023-08-23 广告
要找到做串口联网服务器的公司,你可以采取以下措施:1. 在搜索引擎上输入关键词,例如“串口联网服务器公司”、“串口通信公司”等,并筛选搜索结果。2. 在行业门户网站或专业论坛上搜索相关帖子,向其他用户询问推荐可靠的串口联网服务器公司。3. ...
点击进入详情页
本回答由迪凯特科技(北京)有限公司提供
2011-07-06
展开全部
import java.net.*;
import java.io.*;
public class Server {
public static void main(String[] args) throws IOException {
String s = "";//用stringbuffer试试
String s1 = "";
ServerSocket server = new ServerSocket(60000);
System.out.println("可以开始通信");
try {
Socket socket = server.accept();
System.out.println(socket);
InputStream is = socket.getInputStream();
OutputStream out = socket.getOutputStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(is));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
s = bfr.readLine();
System.out.println("客户端对我说:" + s);//读取客户端信息并输出
if("bye".equals(s)) {
pw.println("bye");
pw.flush();
break;
}
s1 = br.readLine();
pw.println(s1);
pw.flush();
System.out.println("我对客户端说:" + s1);
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
server.close();
}
class Reader extends Thread {
public void run() {
while (true) {
}
}
}
}
import java.net.*;
import java.io.*;
public class Talk {
static InputStream is = null;
static OutputStream out;
static BufferedReader bfr;
static PrintWriter pw;
static BufferedReader pin;
public static void main(String[] args) throws IOException {
Socket socket = new Socket(InetAddress.getByName("localhost"), 60000);
System.out.println(socket);
try {
is = socket.getInputStream();
out = socket.getOutputStream();
bfr = new BufferedReader(new InputStreamReader(is));
pw = new PrintWriter(new OutputStreamWriter(out));
pin = new BufferedReader(new InputStreamReader(System.in));
new Controlaa().start();
while (true) {
String s1 = bfr.readLine();
System.out.println("服务器对我说:" + s1);//读取服务器端发送的信息
if (s1.equals("bye")) {
break;
}
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static class Controlaa extends Thread {
@Override
public void run() {
while (true) {
String s = "";
try {
s = pin.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("我对服务器说:" + s);
pw.println(s);
pw.flush();
}
}
}
}
简单搞了下,读取控制台输入和读取socket都是阻塞操作
另外,团IDC网上有许多产品团购,便宜有口碑
import java.io.*;
public class Server {
public static void main(String[] args) throws IOException {
String s = "";//用stringbuffer试试
String s1 = "";
ServerSocket server = new ServerSocket(60000);
System.out.println("可以开始通信");
try {
Socket socket = server.accept();
System.out.println(socket);
InputStream is = socket.getInputStream();
OutputStream out = socket.getOutputStream();
BufferedReader bfr = new BufferedReader(new InputStreamReader(is));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
s = bfr.readLine();
System.out.println("客户端对我说:" + s);//读取客户端信息并输出
if("bye".equals(s)) {
pw.println("bye");
pw.flush();
break;
}
s1 = br.readLine();
pw.println(s1);
pw.flush();
System.out.println("我对客户端说:" + s1);
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
server.close();
}
class Reader extends Thread {
public void run() {
while (true) {
}
}
}
}
import java.net.*;
import java.io.*;
public class Talk {
static InputStream is = null;
static OutputStream out;
static BufferedReader bfr;
static PrintWriter pw;
static BufferedReader pin;
public static void main(String[] args) throws IOException {
Socket socket = new Socket(InetAddress.getByName("localhost"), 60000);
System.out.println(socket);
try {
is = socket.getInputStream();
out = socket.getOutputStream();
bfr = new BufferedReader(new InputStreamReader(is));
pw = new PrintWriter(new OutputStreamWriter(out));
pin = new BufferedReader(new InputStreamReader(System.in));
new Controlaa().start();
while (true) {
String s1 = bfr.readLine();
System.out.println("服务器对我说:" + s1);//读取服务器端发送的信息
if (s1.equals("bye")) {
break;
}
}
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static class Controlaa extends Thread {
@Override
public void run() {
while (true) {
String s = "";
try {
s = pin.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("我对服务器说:" + s);
pw.println(s);
pw.flush();
}
}
}
}
简单搞了下,读取控制台输入和读取socket都是阻塞操作
另外,团IDC网上有许多产品团购,便宜有口碑
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询