乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      java socket 通信

       履歷館 2011-05-24
      package com.oms;
      import java.net.ServerSocket;
      import java.net.Socket;
       
      public class SocketServer extends java.lang.Thread {
       
          private boolean OutServer = false;
          private ServerSocket server;
          private final int ServerPort = 8888;// 要監(jiān)控的port
       
          public SocketServer() {
              try {
                  server = new ServerSocket(ServerPort);
       
              } catch (java.io.IOException e) {
                  System.out.println("Socket啟動(dòng)有問(wèn)題 !");
                  System.out.println("IOException :" + e.toString());
              }
          }
       
          public void run() {
              Socket socket;
              java.io.BufferedInputStream in;
       
              System.out.println("伺服器已啟動(dòng) !");
              while (!OutServer) {
                  socket = null;
                  try {
                      synchronized (server) {
                          socket = server.accept();
                      }
                      System.out.println("取得連線 : InetAddress = "
                              + socket.getInetAddress());
                      // TimeOut時(shí)間
                      socket.setSoTimeout(15000);
       
                      in = new java.io.BufferedInputStream(socket.getInputStream());
                      byte[] b = new byte[1024];
                      String data = "";
                      int length;
                      while ((length = in.read(b)) > 0)// <=0的話(huà)就是結(jié)束了
                      {
                          data += new String(b, 0, length);
                      }
       
                      System.out.println("我取得的值:" + data);
                      in.close();
                      in = null;
                      socket.close();
       
                  } catch (java.io.IOException e) {
                      System.out.println("Socket連線有問(wèn)題 !");
                      System.out.println("IOException :" + e.toString());
                  }
       
              }
          }
       
          public static void main(String args[]) {
      //     for(int i=0;i<100;i++)
      //     {
      //      SocketClient.writeLog(String.valueOf(i)); 
      //     }
           
              (new SocketServer()).start();
          }
       
      }
       
       
      package com.oms;
      import java.io.BufferedOutputStream;
      import java.io.BufferedWriter;
      import java.io.File;
      import java.io.FileWriter;
      import java.net.InetSocketAddress;
      import java.net.Socket;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      public class SocketClient {
       private String address = "127.0.0.1";// 連線的ip
       private int port = 8888;// 連線的port
       public SocketClient() {
       }
       /***
        * 發(fā)送警告信息
        */
       public void sendAlarmMsg(String msg) {
        Socket client = new Socket();
        InetSocketAddress isa = new InetSocketAddress(this.address, this.port);
        try {
         client.connect(isa, 10000);
         BufferedOutputStream out = new BufferedOutputStream(client
           .getOutputStream());
         // 送出字串
         out.write(msg.getBytes("UTF8"));
         out.flush();
         out.close();
         out = null;
         client.close();
         client = null;
      //   writeLog(msg);
        } catch (java.io.IOException e) {
         String strmsg="Socket連線有問(wèn)題 " + " IOException :" + e.toString();
         writeLog(strmsg);
        }
       }
       
        /**
           * 寫(xiě)入日志
           * */
          private  void writeLog(String str) {     
           SimpleDateFormat date = new SimpleDateFormat(
             "yyyy-MM-dd");
           SimpleDateFormat datetime = new SimpleDateFormat(
             "yyyy-MM-dd HH:mm:ss");
             Date dt=new Date();
             String strNow=date.format(dt);
             String strDateTime=datetime.format(dt);
              String filename = "Socket_"+strNow+ ".log";
      //  String strjarPh=new StructuredPushConsumerImpl().getClass().
      //  getProtectionDomain().getCodeSource().getLocation().getPath().substring(1);
      //  strjarPh=strjarPh.substring(0,strjarPh.lastIndexOf("/")+1);
      //  String flpath=strjarPh + filename;
             
              try {
                  BufferedWriter bufOut;
                  File f = new File(filename);
                  if(f.exists()==true){
                      bufOut = new BufferedWriter(new FileWriter(f,true));
                  }else {
                   f.createNewFile();
                      bufOut = new BufferedWriter(new FileWriter(f));
                  }        
                  bufOut.write(strDateTime+"\t" +str);
                  bufOut.newLine();
                  bufOut.close();        
              } catch(Exception e) {
                  System.out.println("Error");
              }
          } 
      }

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多