package ambow;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class Server {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket(1234);
Socket sk = ss.accept();
BufferedReader du = new BufferedReader
(new InputStreamReader(sk
.getInputStream()));
PrintWriter xie = new PrintWriter(sk.getOutputStream()
, true);
Scanner inputs = new Scanner(System.in);
String s = "";
while (true) {
s = du.readLine();
if (s.equals("exit")) {
xie.println(s);
System.out.println("结束");
du.close();
xie.close();
sk.close();
break;
}
System.out.println("提问:" + s + "\n回答:");
xie.println(inputs.next());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
上面是服务端↑。。。
package ambow;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class Text2 {
public static void main(String[] args) {
try {
Socket sk1 = new Socket("pc43", 1234);
BufferedReader du1 = new BufferedReader(new InputStreamReader(sk1
.getInputStream()));
PrintWriter xie1 = new PrintWriter(sk1.getOutputStream(), true);
Scanner input1 = new Scanner(System.in);
String str = "";
while (true) {
System.out.println("提问:");
xie1.println(input1.next());
str = du1.readLine();
if (str.equals("exit")) {
xie1.close();
du1.close();
sk1.close();
break;
}
System.out.println("回答:" + str);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
上面是客户端↑
客户端里面xie1.println(input1.next());这句到底是什么意思 怎么把客户端的传到服务端,服务端的信息又怎么返回客户端?