You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
994 B
31 lines
994 B
import java.io.BufferedWriter;
|
|
import java.io.IOException;
|
|
import java.io.OutputStreamWriter;
|
|
import java.net.Socket;
|
|
import java.util.Scanner;
|
|
|
|
public class client2 {
|
|
static Scanner sc = new Scanner(System.in);
|
|
public static void main(String[] args) throws IOException {
|
|
Socket socket = new Socket("127.0.0.1", 10005);
|
|
|
|
new Thread(new clientRunable2(socket)).start();
|
|
talk(socket);
|
|
}
|
|
|
|
private static void talk(Socket socket) throws IOException {
|
|
System.out.println("请输入你的用户名:");
|
|
String peoplename=sc.nextLine();
|
|
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
|
|
|
while (true) {
|
|
System.out.println("请输入您要说的话");
|
|
String str = sc.nextLine();
|
|
//把聊天内容写给服务器
|
|
bw.write(peoplename+":"+str);
|
|
bw.newLine();
|
|
bw.flush();
|
|
}
|
|
}
|
|
}
|