网络客户端开发初级小程序

(1)目的:增加对客户端技术的熟练程度
(2)技术:简单的网站开发技术
(3)代码:

public class heget extends Thread{
    Socket socket;
    String name;
    public static ArrayList names=new ArrayList<>();
    public heget(Socket socket,String name){
        this.socket=socket;
        this.name=name;
        names.add(name);
    }
    @Override
    public void run() {
        try {
                BufferedReader mget = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                String mline;
                while ((mline = mget.readLine())!= null) {
                    System.out.println(mline);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {

            }
            super.run();
        }
    }
package monline;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class mprintln extends Thread{
    public static String i="wen";
    public static int location=-1;
    Socket custem;
    public mprintln(Socket custem){
        this.custem=custem;
    }
    @Override
    public void run() {
        try {
                BufferedReader mget = new BufferedReader(new InputStreamReader(custem.getInputStream()));
                String getline=null;
                while ((getline = mget.readLine()) != null) {
                    System.out.println(heget.names.get(mprintln.location));
                    System.out.println(getline);
                    for (Socket temp : serviver.person) {
                            PrintStream mmout = new PrintStream(temp.getOutputStream());
                            mmout.println(getline);

                        }
                    }

            } catch (IOException e) {
            } finally {
                if (custem != null) {
                    try {
                        custem.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            super.run();

    }

}
public class mclient1{
    public static void main(String[] args) throws IOException {
        Socket socket=new Socket("10.129.0.123",10086);
        String mname=shuchu.setname();
        System.out.println(mname);
        new heget(socket,mname).start();
        BufferedReader mget=new BufferedReader(new InputStreamReader(System.in));
        PrintStream mput=new PrintStream(socket.getOutputStream());
        String mline=null;
        while ((mline=mget.readLine())!=null){
            mprintln.location=0;
            mput.println(mline);
        }
    }
}

package monline;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

public class mclient2{
public static void main(String[] args) throws IOException {
Socket socket=new Socket("10.129.0.123",10086);
String mname=shuchu.setname();
System.out.println(mname);
new heget(socket,mname).start();
BufferedReader mget=new BufferedReader(new InputStreamReader(System.in));
PrintStream mput=new PrintStream(socket.getOutputStream());
String mline=null;
while ((mline=mget.readLine())!=null){
mprintln.location=1;
mput.println(mline);

    }
}

}

```package monline;

import java.util.Scanner;

public class shuchu {
    public static String setname(){
        System.out.println("请输入你的名称");
        Scanner read=new Scanner(System.in);
        String temp=read.nextLine();
        return temp;
    }
}

你可能感兴趣的:(网络客户端开发初级小程序)