⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tryclient.java

📁 用java实现的一个bbs的portal
💻 JAVA
字号:
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Jul 19, 2003
 * Time: 6:13:49 PM
 * To change this template use Options | File Templates.
 */
package ConnectAdapter;

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TryClient extends Thread{

    Socket echoSocket;
    PrintWriter out;
    BufferedReader in;
    int selfCount;
    static int count = 0;

    public TryClient(int selfCount){
        this.selfCount = selfCount;
    }

    private void newClient(){
        try{
//创建Socket
            echoSocket = new Socket("162.105.30.254", 2617);
//创建读写对象
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
//利用读写对象,与服务器通信
            out.println("LOGIN%letter%letter");
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    public void run(){
        newClient();
        while(true){
            try{
                String inputLine = in.readLine();
                System.out.println(this.selfCount+" -- Input Message : "+inputLine);
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }
    }

    public static void main(String args[]){
        for (int i = 0;i<500;i++){
            count ++;
            TryClient tryClient = new TryClient(count);
            tryClient.start();
            try{
                Thread.sleep(2000);
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -