📄 myserver.java
字号:
package com.sterning;
import java.io.*;
import java.net.*;
import java.util.*;
public class MyServer {
ServerSocket ss;
Socket s;
ArrayList al = new ArrayList();
ArrayList al1 = new ArrayList();
ArrayList al2 = new ArrayList();
ArrayList alname = new ArrayList();
Socket s1, s2;
MyServer() throws IOException {
ss = new ServerSocket(1004); // create server socket
while (true) {
s = ss.accept(); // accept the client socket
s1 = ss.accept();
s2 = ss.accept();
al.add(s); // add the client socket in arraylist
al1.add(s1);
al2.add(s2);
System.out.println("Client is Connected");
// new thread to maintain the list of user name
MyThread2 m = new MyThread2(s2, al2, alname);
Thread t2 = new Thread(m);
t2.start();
// new thread to receive and send message
MyThread r = new MyThread(s, al);
Thread t = new Thread(r);
t.start();
MyThread1 my = new MyThread1(s1, al1, s, s2);
Thread t1 = new Thread(my);
t1.start();
}
}
public static void main(String[] args) {
try {
new MyServer();
} catch (IOException e) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -