码迷,mamicode.com
首页 > 其他好文 > 详细

GetIp

时间:2014-12-12 19:21:44      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:socket   服务器   public   import   

import java.io.*;
import java.net.*;
public class GetIp {
 public static void main(String args[]){
  try{
   Socket connectToServer = new Socket("127.0.0.1",8234);
   DataInputStream inFromServer = new DataInputStream(connectToServer.getInputStream());
   DataOutputStream outToServer = new DataOutputStream(connectToServer.getOutputStream());
   
   System.out.println("输入半径数值发送到服务器,输入bye结束");
   String outStr,inStr;
   boolean goon = true;
   
   while(goon){
    //BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
    //outStr = buf.readLine();
    //if(outStr.equals("bye"))
     //return;
    //outToServer.writeUTF(outStr);
    try{
    Thread.sleep(1000);
    }catch(InterruptedException e){}
    outToServer.writeUTF("#1122222#11111111111111111#");
    outToServer.flush();
    //inStr = inFromServer.readUTF();
    //if(!inStr.equalsIgnoreCase("bye")){
    // System.out.println("从服务器读到的内容是:"+inStr);
    //}
    //else
    // goon = false;
   
   }
   inFromServer.close();
   outToServer.close();
   connectToServer.close();
  }catch(IOException e){
   e.printStackTrace();
  }
  
 }

}



GetIp

标签:socket   服务器   public   import   

原文地址:http://2172006.blog.51cto.com/2162006/1589419

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!