简介
RT
code
package com.kuang;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
/**
* Created by lee on 2021/4/1.
*/
public class TcpServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(9999);
Socket socket =serverSocket.accept();
InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len;
while((len=is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
System.out.println(baos.toString());
baos.close();
is.close();
socket.close();
serverSocket.close();
}
}
package com.kuang;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
/**
* Created by lee on 2021/4/1.
*/
public class TcpClient {
public static void main(String[] args) throws IOException {
InetAddress serverIP = InetAddress.getByName("127.0.0.1");
int port = 9999;
Socket socket = new Socket(serverIP, port);
OutputStream os = socket.getOutputStream();
os.write("adfdsafdsafda".getBytes());
os.close();
socket.close();
}
}
---------------------------我的天空里没有太阳,总是黑夜,但并不暗,因为有东西代替了太阳。虽然没有太阳那么明亮,但对我来说已经足够。凭借着这份光,我便能把黑夜当成白天。我从来就没有太阳,所以不怕失去。
--------《白夜行》