
如何用一个Socket服务端去接收一个http请求
1个回答
推荐于2016-10-02 · 知道合伙人数码行家

知道合伙人数码行家
采纳数:25897
获赞数:1464999
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注

展开全部
Java code
ServerSocket serverSocket = null;
int port = 8888;
try
{
serverSocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1"));
} catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
while (!shutdown)
{
Socket socket = null;
InputStream input = null;
OutputStream output = null;
try
{
/**
* 循环到此停止,在端口8888接收到一个HTTP请求才会继续
*/
socket = serverSocket.accept();
input = socket.getInputStream();
output = socket.getOutputStream();
} catch (Exception e)
{
e.printStackTrace();
continue;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询