Java Socket??????????????????
???????????? ???????[ 2012/12/4 10:06:23 ] ????????
?????????????
??????????????Hello???????????????IP???????????????κ?????????????????????(Hello?? Java Socket)??????????????????????????????????????????
??????????
??????????????Socket?????Hello??????????????????????????????????????????????????????
????????????
????????JAVA?????????????????????API?????o????????JAVA SOCKET?????????????????????????????????????readline()?????Socket?????????????????????????з???/r/n???????????????????????????????????
?????????Щ??????????????г??????????????????????????а?????????????????????????????????????????????????????????а????????????????????????????з???????????????????Щ??????println()???????????readline()??????????????????????????????????????????Щ?????????????????????????????????????????£??????flush()????????????????????????л???????????????????д????
???????????????
package com.gloomyfish.socket.tutorial.two;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class HelloService extends Thread {
private ServerSocket serverSocket;
public HelloService(int port) throws IOException {
serverSocket = new ServerSocket(port);
}
public void run()
{
try {
while(true)
{
System.out.println("Waiting for client on port " + serverSocket.getLocalPort());
Socket client = serverSocket.accept(); // blocked & waiting for income socket
System.out.println("Just connected to " + client.getRemoteSocketAddress());
DataOutputStream dos = new DataOutputStream(client.getOutputStream());
byte[] hello = "Hello?? Java Socket".getBytes();
dos.write(hello?? 0?? hello.length);
dos.close();
client.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
HelloService service = new HelloService(9999);
service.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
??????????????9999?????????????????Java Thread?????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11