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

📄 simpleserver.java

📁 Socket Server
💻 JAVA
字号:
import java.net.*;
import java.io.*;
public class SimpleServer implements Runnable
{
   int jjj=3;
   ServerSocket s;
   Socket[] s1;
   int index=0;
   public void run()
   {
      for(int i=0;i<jjj;i++)
      {
        try
        {
           s1[index++]=s.accept();
        }
        catch(IOException e)
        {
           System.out.println("Exception caught 2");
        }
      }
   }
   public static void main(String args[])  throws IOException
   {
      SimpleServer Myself=new SimpleServer();
      Myself.xw();
   }
   public void xw()
   {
      String sendString="Hello,net world";
      OutputStream slout;
      DataOutputStream dos;
      try
      {
         s=new ServerSocket(5432);
         s1=new Socket[jjj];
         Thread thread=new Thread(this);
         thread.start();
         BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
         while(!sendString.equals("quit"))
         {
//           BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
             sendString=in.readLine();
             if(sendString.compareTo("quit")!=0)
                System.out.println("not quit");
             else
                System.out.println("quit");
             for(int i=0;i<jjj;i++)
             {
                if(s1[i]==null)
                  break;
                  slout=s1[i].getOutputStream();
                  dos=new DataOutputStream(slout);
                  dos.writeUTF(sendString);
                  System.out.println("Send to Client :"+sendString);
             }
         }
/*         if(dos!=null)
            dos.close();
         if(slout!=null)
            slout.close();
         for(int i=0;i<jjj;i++)
         {
           if(s1[i]!=null)
              s1[i].close();
         }
*/
     }
     catch(IOException e)
     {
        System.out.println("Exception caught 2");
     }
   }
}

⌨️ 快捷键说明

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