JAVA NET

来源:互联网 发布:淘宝美工面试问题 编辑:程序博客网 时间:2024/05/17 01:39
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;


public class client {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Socket soc=null;
try {
soc =new Socket("localhost", 8080);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStreamReader input = null;
try {
input = new InputStreamReader(soc.getInputStream());
BufferedReader data=new BufferedReader(input);
String read=data.readLine();
//从键盘不断读入字符:
byte []bytes=new byte[read.length()];
System.in.read(bytes);
String newdata=new String(bytes);
while(newdata!="quit")
{
System.in.read(bytes);
newdata=new String(bytes);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
input.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
soc.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}

原创粉丝点击