|
package com.renxing.r0039_NetSeapk;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
//Tcp客户端
public class KeHu
{
public static void main(String[] args) throws IOException
{
Socket s=new Socket("localhost",10000);
byte [] bys="Tcp传输协议第一个客户端".getBytes();
OutputStream os=s.getOutputStream();
os.write(bys);
os.close();
}
}
package com.renxing.r0039_NetSeapk;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class FuWu
{
public static void main(String[] args) throws Exception
{
ServerSocket ss=new ServerSocket(10000);
Socket s=ss.accept();
String ip=s.getInetAddress().getHostAddress();
byte [] bys=new byte[1024];
InputStream is=s.getInputStream();
int length=is.read(bys);
String context=new String(bys,0,length);
String port=String.valueOf(ss.getLocalPort());
System.out.println(ip+":"+port+":::"+context);
s.close();
ss.close();
}
} |
|