{"id":69,"date":"2013-07-10T22:42:49","date_gmt":"2013-07-10T13:42:49","guid":{"rendered":"http:\/\/www.rocher.kyoto.jp\/araburu\/?p=69"},"modified":"2013-07-11T12:01:35","modified_gmt":"2013-07-11T03:01:35","slug":"websocketjsr-356%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b%e3%80%82%e3%81%9d%e3%81%ae2","status":"publish","type":"post","link":"https:\/\/www.rocher.kyoto.jp\/arbr\/?p=69","title":{"rendered":"WebSocket(JSR 356)\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u305d\u306e2"},"content":{"rendered":"<p><a title=\"WebSocket(JSR 356)\u3092\u4f7f\u3063\u3066\u307f\u308b\u3002\u305d\u306e\uff11\uff08\u307e\u305a\u306f\u8efd\u304f\u89e6\u308c\u3066\u307f\u308b\uff09\" href=\"https:\/\/www.rocher.kyoto.jp\/araburu\/?p=62\">\u5148\u65e5<\/a>\u306b\u7d9a\u304d<a href=\"http:\/\/www.oracle.com\/technetwork\/articles\/java\/jsr356-1937161.html\">Oracle\u306e\u30b5\u30a4\u30c8<\/a>\u3092\u307f\u306a\u304c\u3089\u307c\u3061\u307c\u3061\u8a66\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p><strong><code>@OnMessage\u306e\u623b\u308a\u5024<\/code><\/strong><\/p>\n<p>If the return type of the method annotated with <code>@OnMessage<\/code> is not <code>void<\/code>, the WebSocket implementation will send the return value to the other <span style=\"color: #ff0000;\">peer<\/span>.<\/p>\n<p>\u623b\u308a\u5024\u4ed8\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u5834\u5408\u3001\u305d\u306e\u5024\u3092peer\u306b\u8fd4\u3059\u3068\u3044\u3046\u3088\u3046\u306a\u4e8b\u304c\u66f8\u3044\u3066\u3042\u308b\u306e\u3067\u8a66\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>\uff08<a href=\"https:\/\/www.rocher.kyoto.jp\/araburu\/wp-content\/uploads\/2013\/07\/retValTest.zip\">\u30bd\u30fc\u30b9<\/a>\uff09<\/p>\n<p>@OnMessage<br \/>\npublic <span style=\"color: #ff0000;\">String<\/span> onMessage(String message) {<br \/>\nSystem.out.println(&#8220;message[&#8221; + message + &#8220;]&#8221;);<br \/>\n<span style=\"color: #ff0000;\">\u00a0return message;<\/span><br \/>\n}<\/p>\n<p>\u5b9f\u969b\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u3063\u305f\u30d6\u30e9\u30a6\u30b6\u306b\u306f\u623b\u308a\u5024\u304c\u5e30\u3063\u3066\u304d\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.rocher.kyoto.jp\/araburu\/wp-content\/uploads\/2013\/07\/a2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-71\" alt=\"\u623b\u308a\u5024\u78ba\u8a8d\" src=\"https:\/\/www.rocher.kyoto.jp\/araburu\/wp-content\/uploads\/2013\/07\/a2-300x139.png\" width=\"439\" height=\"203\" srcset=\"https:\/\/www.rocher.kyoto.jp\/arbr\/wp-content\/uploads\/2013\/07\/a2-300x139.png 300w, https:\/\/www.rocher.kyoto.jp\/arbr\/wp-content\/uploads\/2013\/07\/a2.png 567w\" sizes=\"auto, (max-width: 439px) 100vw, 439px\" \/><\/a><\/p>\n<p>\u305f\u3060\u3057\u3001\u958b\u3044\u3066\u3044\u305f\u4ed6\u306e\u30d6\u30e9\u30a6\u30b6\u306b\u306f\u9001\u4fe1\u3055\u308c\u3066\u3044\u306a\u3044\u3002<\/p>\n<p><a href=\"https:\/\/www.rocher.kyoto.jp\/araburu\/wp-content\/uploads\/2013\/07\/b1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-72\" alt=\"\u5225\u30d6\u30e9\u30a6\u30b6\u3078\u306e\u53cd\u6620\u72b6\u6cc1\" src=\"https:\/\/www.rocher.kyoto.jp\/araburu\/wp-content\/uploads\/2013\/07\/b1-300x190.png\" width=\"384\" height=\"243\" srcset=\"https:\/\/www.rocher.kyoto.jp\/arbr\/wp-content\/uploads\/2013\/07\/b1-300x190.png 300w, https:\/\/www.rocher.kyoto.jp\/arbr\/wp-content\/uploads\/2013\/07\/b1-624x395.png 624w, https:\/\/www.rocher.kyoto.jp\/arbr\/wp-content\/uploads\/2013\/07\/b1.png 715w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">peer<\/span>\u3068\u66f8\u3044\u3066\u3044\u308b\u3060\u3051\u306a\u306e\u3067\u8907\u6570\u306b\u8fd4\u3059\u306e\u3067\u306a\u304f\u5358\u72ec\u306e\u3082\u306e\u306b\u8fd4\u3059\u3068\u3044\u3046\u52d5\u4f5c\u3068\u3044\u3046\u8a8d\u8b58\u3067\u3042\u3063\u3066\u3044\u308b\u306e\u304b\u306a\uff1f\uff1f<\/p>\n<p>\u7591\u554f\u306f\u6b8b\u308b\u3051\u3069\u3001\u8907\u6570\u30d6\u30e9\u30a6\u30b6(peer)\u306b\u8fd4\u3059\u30b5\u30f3\u30d7\u30eb\u304c\u3042\u308b<code><strong><a href=\"http:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/websocket\/Session.html#getAsyncRemote%28%29\">getAsyncRemote<\/a><\/strong><\/code>\u3001<code><strong><a href=\"http:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/websocket\/Session.html#getBasicRemote%28%29\">getBasicRemote<\/a><\/strong>()<\/code>\u3092\u8a66\u3057\u3066\u307f\u308b\u3002API\u306b\u3088\u308b\u3068\u975e\u540c\u671f\u304b\u540c\u671f\u304b\u306e\u9055\u3044\u3089\u3057\u3044\u3002<\/p>\n<p><strong><code>\u00a0<strong><code>@OnMessage\u306egetAsyncRemote\/getBasicRemote<\/code><\/strong><\/code><\/strong><\/p>\n<p>\u30bd\u30fc\u30b9\u3092\u66f8\u304d\u63db\u3048\u3066\u307f\u305f\u3051\u308c\u3069\u3082\u3001<strong><code><strong><code>getAsyncRemote<\/code><\/strong><\/code><\/strong>\u3068<strong><code><strong><code>getBasicRemote<\/code><\/strong><\/code><\/strong>\u306e\u4e21\u65b9\u3068\u3082\u540c\u6642\u306b<span style=\"color: #000000;\">alert(&#8220;Calling&#8221;);\u307e\u3067\u9032\u3080\u3002<\/span><\/p>\n<p><code><a title=\"interface in javax.websocket\" href=\"http:\/\/docs.oracle.com\/javaee\/7\/api\/javax\/websocket\/RemoteEndpoint.Basic.html\">RemoteEndpoint.Basic<\/a><\/code>\u3092\u307f\u308b\u3068\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304b\u308c\u3066\u3044\u308b\u306e\u3067\u306e\u3067JS\u306eAlert\u6587\u3067\u5f85\u3061\u304c\u5165\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u3089\u3057\u3044\u3002<\/p>\n<p>The point of completion of the send is defined when all the supplied data has been written to the underlying connection<\/p>\n<p>\u9001\u4fe1\u5931\u6557\u306b\u5099\u3048\u305f\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u3059\u308b\u305f\u3081\u306e\u3082\u306e\u3067\u3001Endpoint\u9593\u306e\u540c\u671f\u3092\u3068\u308b\u76ee\u7684\u3067\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3088\u3044\u306e\u304b\u306a\u3002<\/p>\n<p>(java)<\/p>\n<p>static Set&lt;Session&gt; sessions = Collections<br \/>\n.synchronizedSet(new HashSet&lt;Session&gt;());<\/p>\n<p>@OnMessage<br \/>\npublic void onMessage(String message) {<br \/>\nSystem.out.println(&#8220;message[&#8221; + message + &#8220;]&#8221;);<br \/>\nfor (Session s : sessions) {<br \/>\ns.<span style=\"color: #ff0000;\">getAsyncRemote<\/span>().sendText(message);<br \/>\n}<br \/>\n}<\/p>\n<p>@OnMessage<br \/>\npublic void onMessage(String message) throws IOException {<br \/>\nSystem.out.println(&#8220;message[&#8221; + message + &#8220;]&#8221;);<br \/>\nfor (Session s : sessions) {<br \/>\ns.<span style=\"color: #ff0000;\">getBasicRemote<\/span>().sendText(message);<br \/>\n}<br \/>\n}<\/p>\n<p>\uff08JS\uff09<\/p>\n<p>socket.onmessage = function(message){<br \/>\n<span style=\"color: #ff0000;\">alert(&#8220;Calling&#8221;);<\/span><br \/>\n$(&#8216;#log&#8217;).append(message.data + &#8220;&lt;br\/&gt;&#8221;);<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u65e5\u306b\u7d9a\u304dOracle\u306e\u30b5\u30a4\u30c8\u3092\u307f\u306a\u304c\u3089\u307c\u3061\u307c\u3061\u8a66\u3057\u3066\u3044\u304d\u307e\u3059\u3002 @OnMessage\u306e\u623b\u308a\u5024 If the return type of the method annotated with @OnMessage is  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[8,9,70,7,6],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-javaee","tag-annotation","tag-glassfish","tag-javaee","tag-jsr-356","tag-websocket"],"_links":{"self":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69"}],"version-history":[{"count":14,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":74,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions\/74"}],"wp:attachment":[{"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rocher.kyoto.jp\/arbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}