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

📄 chatseverthree.java

📁 初学java,最近帮同学作的一些实验
💻 JAVA
字号:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;

public class chatseverthree implements Runnable{

	 public static final int PORT=1234;
	 protected ServerSocket listen;
	 static Vector connections;
	 Thread connect;
	 
	 public chatseverthree()
	 {
		 try{
			 listen=new ServerSocket(PORT);
		 }catch(UnknownHostException e2){
			 System.out.println("erro:"+e2);
		 }
		 catch(IOException e){
			 System.out.println("erro:"+e);
			 System.exit(1);
		 }
		 connections=new Vector(1000);
		 connect=new Thread(this);
		 System.out.println(13);
		 connect.start();
	 }
	 public static void main(String args[])
	 {
		 new chatseverthree();
		 System.out.println("starting.....");
	 }
	 public void run()
	 {
		 try{
			 while(true)
			 {   //System.out.println(12);
				 Socket client =listen.accept();
				 System.out.println(1);
				 firstthread f=new firstthread(this,client);
				 //f.setPriority(Thread.MIN_PRIORITY);
				 f.start();
				 connections.addElement(f);
			 }
		 }catch(IOException e){
			 System.out.println("erro:"+e);
			 System.exit(1);
		 }	 
	 }
	 public void broadcast(String msg)
	 {
		int i;
		//System.out.println("cast");
		firstthread you;
		for(i=0;i<connections.size();i++)
		{
			you=(firstthread)connections.elementAt(i);
			try{
				you.out.writeUTF(msg);
			}catch(IOException e){}
		}
	 }
	 public void broadcast1(String msg)
	 {
		 int i;
		 String s1,s2,s3;
		 firstthread you;
		 s1 = new String("people");
		 s2=new String(msg.substring(4));
		 s3=s1.concat(s2);
		 for(i=0;i<connections.size();i++)
		 {
			 you=(firstthread)connections.elementAt(i);
			 if(s3.startsWith(you.name))
			 {
				 try{
					 you.out.writeUTF(msg);
				 }catch(IOException e){}
			 }
		 }
	 }
}

⌨️ 快捷键说明

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