Java中Socket的用法有以下几种:
Socket clientSocket = new Socket();
clientSocket.connect(new InetSocketAddress("服务器IP地址", 端口号));
ServerSocket serverSocket = new ServerSocket(端口号);
Socket clientSocket = serverSocket.accept();
// 客户端发送数据
OutputStream outputStream = clientSocket.getOutputStream();
outputStream.write(数据字节流);
// 服务器端接收数据
InputStream inputStream = clientSocket.getInputStream();
byte[] buffer = new byte[1024];
int length = inputStream.read(buffer);
clientSocket.close();
以上是Java Socket的基本用法,可以根据具体需求进行扩展和优化。