本帖最后由 何羡玉 于 2013-4-28 21:24 编辑
谁知道这是怎么回事
package sockedTest;
import java.io.*;
import java.net.*;
public class server {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
ServerSocket ss=new ServerSocket (18000);
Socket s=ss.accept();
InputStream in= s.getInputStream();
OutputStream out=s.getOutputStream();
byte[] b=new byte[1024*64];
int len=in.read(b);
out.write("客户端,你好".getBytes());
System.out.println(new String(b,0,len));
s.close();
}
}
package sockedTest;
import java.io.*;
import java.io.InputStream;
import java.net.*;
public class client {
public static void main(String[] args) throws UnknownHostException, IOException
{
Socket s=new Socket("127.0.0.1",18000);
InputStream in= s.getInputStream();
OutputStream out=s.getOutputStream();
byte[] b=new byte[1024*64];
int len= in.read(b);
System.out.print(new String (b,0,len));
out.write("服务端,你好".getBytes());
s.close();
}
}
|