package WLBC4;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
public class TCPsent {
public static void main(String[] args) throws IOException {
Socket s = new Socket("192.168.22.28",12347);
OutputStream os = s.getOutputStream();
os.write("tcp你是谁".getBytes());
s.close();
}
}
package WLBC4;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class TCPreceive {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(12347);
Socket s = ss.accept();
InputStream is = s.getInputStream();
byte [] bys = new byte[1024];
int len = is.read(bys);
String data = new String(bys,0,len);
System.out.println("数据是:"+data);
s.close();
ss.close();
}
}
|
|