class tcpSocket {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket soc=new Socket("10.10.1.172", 10001);
OutputStream out=soc.getOutputStream();
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
//InputStream input=soc.getInputStream();
String line=null;
while((line=read.readLine())!=null){
if("886".equals(line))
break;
out.write(line.getBytes());
// byte[] buf=new byte[1024];
// int len=input.read(buf);
//System.out.println(new String(buf,0,len));
}
read.close();
soc.close();
}
}
class tcpServer {
public static void main(String[] args) throws IOException {
ServerSocket server=new ServerSocket(10001);
Socket soc=server.accept();
String s=soc.getInetAddress().getHostAddress();
System.out.println("已连接"+s);
InputStream input=soc.getInputStream();
byte[] buf=new byte[1024];
int len=input.read(buf);
System.out.println(new String(buf,0,len));
/*
OutputStream out=soc.getOutputStream();
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
String line=null;
while((line=read.readLine())!=null){
if("886".equals(line))
//break;
byte[] by=new byte[1024];
out.write(line.getBytes());
}
*/
//read.close();
soc.close();
}
}
报错:Exception in thread "main" java.net.SocketException: Software caused connection abort: socket write error
|
|