diff --git a/client2.java b/client2.java new file mode 100644 index 0000000..e638595 --- /dev/null +++ b/client2.java @@ -0,0 +1,30 @@ +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(); + } + } +}