欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java socket

程序员文章站 2022-05-28 19:54:25
...

public void dotest()
    {
     SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
     Socket socket = null;
     String ip = "10.243.215.139";
     //String ip = "127.0.0.1";
     int port = 7101;
     //int port = 8080;
     
     for(;true;) {
      try {
       socket = new Socket(ip, port);
       String string="socket连接ip:"+ ip+",端口:"+port+",成功:time:" + formatDate.format(new Date()) + " " + socket.isConnected();
          System.out.println(string);
          LogUtil.sokecttest(string);
          socket.close();
          Thread.sleep(10000);
   } catch (Exception e) {
    String s1="socket连接ip:"+ ip+",端口:"+port+",错误:" + formatDate.format(new Date()) + " " + e.toString();
    System.out.println(s1);
    LogUtil.sokecttest(s1);
   }
      
     }
    }

相关标签: dotest