• R/O
  • SSH
  • HTTPS

webserver: Commit


Commit MetaInfo

Revision70 (tree)
Time2011-06-03 00:17:57
Authorhoritaku

Log Message

WebSocket周り修正

Change Summary

Incremental Difference

--- branch/Basic 0.2x/sokect_action/socket_action/WebTest2.java (nonexistent)
+++ branch/Basic 0.2x/sokect_action/socket_action/WebTest2.java (revision 70)
@@ -0,0 +1,68 @@
1+package socket_action;
2+
3+import java.io.IOException;
4+import java.io.InputStream;
5+import java.io.OutputStream;
6+
7+import servercore.http.HttpRequest;
8+
9+public class WebTest2 {
10+ private OutputStream ops = null;
11+ private InputStream ips = null;
12+ public boolean cont = true;
13+ public static String A = "";
14+ private String B = null;
15+ public void execute(HttpRequest req, OutputStream ops, InputStream ips) {
16+ this.ops = ops;
17+ this.ips = ips;
18+ System.out.println("\r\nWebTest start");
19+ B = WebTest2.A;
20+ SyncsThread th = new SyncsThread();
21+ th.start();
22+ try {
23+ while(cont) {
24+ WebTest2.A = read();
25+ //send(str);
26+ }
27+ } catch(IOException e) {
28+ e.printStackTrace();
29+ }
30+ System.out.println("\r\nWebTest end");
31+ }
32+ class SyncsThread extends Thread {
33+ public void run() {
34+ try {
35+ while(true){
36+ if(WebTest2.A != B) {
37+ send(WebTest2.A);
38+ B = WebTest2.A;
39+ }
40+ Thread.sleep(10);
41+ }
42+ }catch(Exception e) {
43+ e.fillInStackTrace();
44+ }
45+
46+ }
47+ }
48+ public String read() throws IOException{
49+ byte[] data = new byte[8098];
50+ int len = ips.read(data);
51+ String str = "";
52+ if(data[0] == 0 && data[len - 1] == -1) {
53+ str = new String(data, 1, len - 2);
54+ }
55+ return str;
56+ }
57+
58+ public void send(String str) throws IOException {
59+ if(ops == null) {
60+ return;
61+ }
62+ ops.write(0x00);
63+ ops.write(str.getBytes());
64+ ops.write(0xff);
65+ ops.flush();
66+
67+ }
68+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- branch/Basic 0.2x/sokect_action/socket_action/WebTest.java (revision 69)
+++ branch/Basic 0.2x/sokect_action/socket_action/WebTest.java (revision 70)
@@ -12,29 +12,29 @@
1212 public void execute(HttpRequest req, OutputStream ops, InputStream ips) {
1313 this.ops = ops;
1414 System.out.println("\r\nWebTest start");
15- while(cont) {
16- try {
17- Thread.sleep(2000);
18- send(String.valueOf(System.currentTimeMillis()));
19- } catch (InterruptedException e) {
20- // TODO 自動生成された catch ブロック
21- e.printStackTrace();
15+ try {
16+ while(cont) {
17+ try {
18+ Thread.sleep(2000);
19+ send(String.valueOf(System.currentTimeMillis()));
20+ } catch (InterruptedException e) {
21+ e.printStackTrace();
22+ }
2223 }
24+ } catch(IOException e) {
25+ e.printStackTrace();
2326 }
2427 System.out.println("\r\nWebTest end");
2528 }
2629
27- public static void send(String str) {
30+ public static void send(String str) throws IOException {
2831 if(ops == null) {
2932 return;
3033 }
31- try {
32- ops.write(0x00);
33- ops.write(str.getBytes());
34- ops.write(0xff);
35- ops.flush();
36- } catch (IOException e) {
37- e.printStackTrace();
38- }
34+ ops.write(0x00);
35+ ops.write(str.getBytes());
36+ ops.write(0xff);
37+ ops.flush();
38+
3939 }
4040 }
--- branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 69)
+++ branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 70)
@@ -28,6 +28,8 @@
2828 HttpRequest req = analyzeReq(ips);
2929 req.normarizePath(HttpServer.getRootDirPath());
3030 String ext = req.getExtesion();
31+
32+ // レスポンスを圧縮(gzip)して送信するか
3133 boolean useGzip = useEncodingOK(req.getHeader().get("Accept-Encoding"),
3234 HttpServer.getUseCompress());
3335
--- branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 69)
+++ branch/Basic 0.2x/src/servercore/job/GeneratePage.java (revision 70)
@@ -113,11 +113,11 @@
113113
114114 Class<Action> cls = null;
115115
116- cls = (Class<Action>)Class.forName(PackageName);
117- Method method = cls.getMethod("execute", HttpRequest.class, OutputStream.class, InputStream.class);
118- // 実行する
119- method.invoke(cls.newInstance(), req, ops, ips);
120- }
116+ cls = (Class<Action>)Class.forName(PackageName);
117+ Method method = cls.getMethod("execute", HttpRequest.class, OutputStream.class, InputStream.class);
118+ // 実行する
119+ method.invoke(cls.newInstance(), req, ops, ips);
120+ }
121121 public static byte[] getChalengeKey(byte[] header) {
122122 byte[] ret = null;
123123 try {
--- branch/Basic 0.2x/docRoot2/text.html (nonexistent)
+++ branch/Basic 0.2x/docRoot2/text.html (revision 70)
@@ -0,0 +1,38 @@
1+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3+
4+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
5+<head>
6+<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8"/>
7+<meta http-equiv="Content-Style-Type" content="text/css" />
8+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9+<meta http-equiv="Content-Script-Type" content="text/javascript" />
10+
11+<script type="text/javascript" src="js/jquery.js"></script>
12+<script>
13+<!--
14+var host = location.host;
15+var ws = new WebSocket("ws://" + host + "/WebTest2.ws");
16+ws.onmessage = function(msg) {
17+ document.getElementById('test').innerHTML = "<p>" + msg.data + "</p>";
18+}
19+ws.onopen = function(){
20+ ws.send('message');
21+ document.getElementById('massage').innerHTML = "通信開始";
22+}
23+function ch(){
24+ ws.send(document.getElementById('txt').value);
25+}
26+ -->
27+</script>
28+<title>テキストの共同編集</title>
29+
30+</head>
31+
32+<body>
33+<p>これはメイン画面です。</p>
34+<p id="massage"></p>
35+<div id="test"></div>
36+<textarea id="txt" onchange="ch()"></textarea>
37+</body>
38+</html>
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- branch/Basic 0.2x/docRoot2/index.html (revision 69)
+++ branch/Basic 0.2x/docRoot2/index.html (revision 70)
@@ -11,7 +11,8 @@
1111 <script type="text/javascript" src="js/jquery.js"></script>
1212 <script>
1313 <!--
14-var ws = new WebSocket("ws://localhost/WebTest.ws");
14+var host = location.host;
15+var ws = new WebSocket("ws://" + host + "/WebTest.ws");
1516 ws.onmessage = function(msg) {
1617 document.getElementById('test').innerHTML += "<p>" + msg.data + "</p>";
1718 }
Show on old repository browser