{"id":42236,"date":"2024-12-01T13:12:28","date_gmt":"2024-12-01T05:12:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42236\/"},"modified":"2024-12-01T13:12:28","modified_gmt":"2024-12-01T05:12:28","slug":"%e5%a6%82%e4%bd%95%e4%b8%ba%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%8f%91%e9%80%81%e4%ba%8b%e4%bb%b6%ef%bc%88sse%e3%80%81eventstream%ef%bc%89%e9%85%8d%e7%bd%aeiis%e7%9a%84httpplatformhandler","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42236\/","title":{"rendered":"\u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler<\/span><\/p>\n<h1>\u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 09:42:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7c73\u4e91\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u76ee\u524d\u6211\u6709\u4e00\u4e2a\u63d0\u4f9b sse \u4f5c\u4e3a\u670d\u52a1\u7684\u7a0b\u5e8f\uff0c\u5e76\u4e14\u6211\u5fc5\u987b\u90e8\u7f72\u5728 iis \u4e0a\u3002\u4f46\u5b83\u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c \u8fd9\u662f\u6211\u5728\u6ca1\u6709 iis \u7684\u60c5\u51b5\u4e0b\u8fd0\u884c .exe \u65f6\u7684\u7ed3\u679c\u3002 <\/p>\n<pre>data: hello, world<\/pre>\n<p>\u4f46\u662f\u5f53\u5b83\u5728 iis \u540e\u9762\u8fd0\u884c\u65f6\uff0c\u6d4f\u89c8\u5668\u5728\u52a0\u8f7d\u65f6\u5361\u4f4f\u4e86\u3002 \u6211\u5fc5\u987b\u5237\u65b0\u4e8b\u4ef6 <code>hello, world<\/code> \u6570\u5343\u6b21\u624d\u80fd\u4f7f iis \u5c06\u7ed3\u679c\u5237\u65b0\u5230\u6d4f\u89c8\u5668\uff0c\u5e76\u4e14\u5b83\u4f1a\u7acb\u5373\u5237\u65b0\uff0c\u800c\u4e0d\u662f\u50cf sse \u90a3\u6837\u8fdb\u884c\u589e\u91cf\u66f4\u65b0\u3002 <\/p>\n<p>\u8fd9\u662f\u6211\u7684 <code>web.config<\/code> <\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n    &lt;configuration&gt;\n      &lt;system.webserver&gt;\n        &lt;handlers&gt;\n          &lt;add name=\"httpplatformhandler\" path=\"*\" verb=\"*\" modules=\"httpplatformhandler\" resourcetype=\"unspecified\" \/&gt;\n        &lt;\/handlers&gt;\n        &lt;httpplatform processpath=\".\\sse_server.exe\" \n          arguments=\"-port=%http_platform_port% -environment development\" \n          stdoutlogenabled=\"false\" \n          requesttimeout=\"00:05:00\" \n          stdoutlogfile=\".\\sse_server_log\"&gt;\n        &lt;\/httpplatform&gt;\n        &lt;urlcompression dostaticcompression=\"true\" dodynamiccompression=\"false\" \/&gt;\n        &lt;caching enabled=\"false\" enablekernelcache=\"false\" \/&gt;\n      &lt;\/system.webserver&gt;\n    &lt;\/configuration&gt;<\/pre>\n<p>\u8fd9\u662f\u6211\u7684 <code>go<\/code> \u4ee3\u7801<\/p>\n<pre>func SSEHello(rw http.ResponseWriter, flusher http.Flusher) {\n    rw.Header().Set(\"Content-Type\", \"text\/event-stream; charset=utf-8\")\n    rw.Header().Set(\"Cache-Control\", \"no-cache\")\n    rw.Header().Set(\"Connection\", \"keep-alive\")\n    rw.WriteHeader(http.StatusOK)\n    for i := 0; i &lt; 1000; i++ {\n        rw.Write([]byte(\"data:Hello, world\\n\\n\"))\n        flusher.Flush()\n        time.Sleep(time.Millisecond * 100)\n    }\n}<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u5b9e\u9645\u4e0a httpplatformhandler \u6709  \uff0c\u6240\u4ee5\u6211\u7684\u6d88\u606f\u6ca1\u6709\u7acb\u5373\u53d1\u9001\u51fa\u53bb\u3002 <\/p>\n<p>\u6211\u5fc5\u987b\u66f4\u6539\uff0c \u6240\u4ee5 <code>web.config<\/code> \u5fc5\u987b\u66f4\u65b0\u4e3a\u6b64\u3002<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n    &lt;configuration&gt;\n      &lt;system.webserver&gt;\n        &lt;handlers&gt;\n          &lt;add name=\"aspnetcore\" path=\"*\" verb=\"*\" modules=\"aspnetcoremodule\" resourcetype=\"unspecified\" \/&gt;\n        &lt;\/handlers&gt;\n        &lt;aspnetcore processpath=\".\\sse_server.exe\"  \/&gt;\n      &lt;\/system.webserver&gt;\n    &lt;\/configuration&gt;<\/pre>\n<p>\u8981\u5728 <code>iis<\/code> \u4e0a\u542f\u52a8 <code>go<\/code> \u7684\u5e94\u7528\u7a0b\u5e8f\u4f5c\u4e3a <code>aspnetcore<\/code> \uff0c\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u83b7\u53d6\u73af\u5883\u53d8\u91cf\u540d\u79f0 <code>aspnetcore_port<\/code> \u7136\u540e\u5728\u8be5\u7aef\u53e3\u4e0a\u542f\u52a8 http \u670d\u52a1\u3002 <\/p>\n<pre>port := os.Getenv(\"ASPNETCORE_PORT\")\nhttp.ListenAndServe(\":\"+port, nil)<\/pre>\n<p>\u4ec5\u6b64\u800c\u5df2\uff01<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591aGolang\u77e5\u8bc6\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler \u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler \u6765\u6e90\uff1astackoverflow 2024-04-23 09:42:35 0\u6d4f\u89c8 \u6536\u85cf \u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7c73\u4e91\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300a\u5982\u4f55\u4e3a\u670d\u52a1\u5668\u53d1\u9001\u4e8b\u4ef6\uff08SSE\u3001EventStream\uff09\u914d\u7f6eIIS\u7684HTTPPlatformHandler\u300b\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 \u95ee\u9898\u5185\u5bb9 \u76ee\u524d\u6211\u6709\u4e00\u4e2a\u63d0\u4f9b sse \u4f5c\u4e3a\u670d\u52a1\u7684\u7a0b\u5e8f\uff0c\u5e76\u4e14\u6211\u5fc5\u987b\u90e8\u7f72\u5728 iis \u4e0a\u3002\u4f46\u5b83\u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c \u8fd9\u662f\u6211\u5728\u6ca1\u6709 iis \u7684\u60c5\u51b5\u4e0b\u8fd0\u884c .exe \u65f6\u7684\u7ed3\u679c\u3002 data: hello, world \u4f46\u662f\u5f53\u5b83\u5728 iis \u540e\u9762\u8fd0\u884c\u65f6\uff0c\u6d4f\u89c8\u5668\u5728\u52a0\u8f7d\u65f6\u5361\u4f4f\u4e86\u3002 \u6211\u5fc5\u987b\u5237\u65b0\u4e8b\u4ef6 hello, world \u6570\u5343\u6b21\u624d\u80fd\u4f7f iis \u5c06\u7ed3\u679c\u5237\u65b0\u5230\u6d4f\u89c8\u5668\uff0c\u5e76\u4e14\u5b83\u4f1a\u7acb\u5373\u5237\u65b0\uff0c\u800c\u4e0d\u662f\u50cf sse \u90a3\u6837\u8fdb\u884c\u589e\u91cf\u66f4\u65b0\u3002 \u8fd9\u662f\u6211\u7684 web.config &lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt; &lt;configuration&gt; &lt;system.webserver&gt; &lt;handlers&gt; &lt;add name=&#8221;httpplatformhandler&#8221; path=&#8221;*&#8221; verb=&#8221;*&#8221; modules=&#8221;httpplatformhandler&#8221; resourcetype=&#8221;unspecified&#8221; \/&gt; &lt;\/handlers&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42236","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=42236"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42236\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}