925 バイト追加
、 2020年2月15日 (土) 07:33
==Java HTTPリクエスト確認==
[Java][コード片]
import java.io.InputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerSocketSample {
public static void main(String[] args) {
try {
ServerSocketSample me = new ServerSocketSample();
me.start();
} catch (Exception e) {
e.printStackTrace();
}
}
public void start() throws Exception {
InetAddress addr = InetAddress.getByName("localhost");
ServerSocket server = new ServerSocket(8080,0, addr);
Socket sock = null;
while (true) {
sock = server.accept();
InputStream in = sock.getInputStream();
int c = 0;
while( (c = in.read()) > 0) {
System.out.print((char)c);
}
}
}
}