我有这个服务器(java):
ServerSocket s = new ServerSocket(8080);
Socket accept = s.accept();
InputStream inputStream = accept.getInputStream();
while (inputStream.available() > 0) {
char b = (char) inputStream.read();
System.out.print(b);
}
System.out.println("finish recieve");
System.out.println("start write");
OutputStream outputStream = accept.getOutputStream();
outputStream.write("HTTP/1.1 200 OK\r\n\r\n asdf".getBytes());
System.out.println("data sent to client");
outputStream.flush();
accept.close();
这个客户端(delphi):
if not InternetWriteFile(hRequest, pchar(json.DelimitedText), length(json.DelimitedText), count) then
showmessage('Send content problem: ' + inttostr(getlasterror));
showmessage('Wait for server to send data');
if not InternetGetLastResponseInfo(statusCode, resp, read) then
showmessage('Error '+IntToStr(GetLastError));
showmessage('response-size:' + inttostr(read));
if not HttpEndRequest(hRequest,nil,0,0) then
showmessage('Send end problem: ' + inttostr(getlasterror));
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hConn);
我运行服务器,而不是客户端。
客户端最终向我显示了对话框Wait for server to send data
。
我检查Java-Server,最后一行是
start write
data sent to client
好的,我假设客户端收到内部缓冲区中的数据。我按下对话框,但下一个对话框是response-size:0
。
如何接收客户端中的hello
?