import java.net.*;
import java.io.*;
class Client
{
public static void main (String [] args)throws Exception
{
Socket s=new Socket("172.16.57.35",15455);
OutputStream out=s.getOutputStream();
out.write("客户端发送".getBytes());
InputStream in=s.getInputStream();
byte []buf=new byte[1024];
int len=in.read(buf);
System.out.println(new String(buf,0,len));
s.close();
}
}
class Server
{
public static void main (String [] args)throws Exception
{
ServerSocket ss=new ServerSocket(15455);
Socket s=ss.accept();
InputStream in=s.getInputStream();
byte [] buf=new byte[1024];
int len=in.read(buf);
System.out.println(new String(buf,0,len));
OutputStream out=s.getOutputStream();
out.write("服务端收到".getBytes());
s.close();
ss.close();
}
}
为什么传输失败 |
|