質問編集履歴
1
今回のエラーでは無関係かもしれませんが、index.htmlも追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,9 +48,9 @@
|
|
48
48
|
|
49
49
|
### 該当のソースコード
|
50
50
|
|
51
|
+
app.js
|
51
52
|
|
52
|
-
|
53
|
-
```
|
53
|
+
```javascript
|
54
54
|
|
55
55
|
var http = require('http');
|
56
56
|
|
@@ -84,6 +84,94 @@
|
|
84
84
|
|
85
85
|
```
|
86
86
|
|
87
|
+
index.html
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
<!DOCTYPE html>
|
92
|
+
|
93
|
+
<html lang="ja">
|
94
|
+
|
95
|
+
<head>
|
96
|
+
|
97
|
+
<meta charset="utf-8">
|
98
|
+
|
99
|
+
<title>websocket-chat</title>
|
100
|
+
|
101
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
|
102
|
+
|
103
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
104
|
+
|
105
|
+
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
|
106
|
+
|
107
|
+
</head>
|
108
|
+
|
109
|
+
<body>
|
110
|
+
|
111
|
+
<div class="container">
|
112
|
+
|
113
|
+
<h1>WebSocket-Chat</h1>
|
114
|
+
|
115
|
+
<form class="form-inline">
|
116
|
+
|
117
|
+
<div class="form-group">
|
118
|
+
|
119
|
+
<label for="msgForm">メッセージ:</label>
|
120
|
+
|
121
|
+
<input type="text" class="form-control" id="msgForm">
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
<button type="submit" class="btn btn-primary">送信</button>
|
126
|
+
|
127
|
+
</form>
|
128
|
+
|
129
|
+
<div id="chatLogs"></div>
|
130
|
+
|
131
|
+
</div>
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
<script type="text/javascript">
|
136
|
+
|
137
|
+
var socket = io.connect();
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
socket.on("server_to_client", function(data){appendMsg(data.value)});
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
function appendMsg(text) {
|
146
|
+
|
147
|
+
$("#chatLogs").append("<div>" + text + "</div>");
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
$("form").submit(function(e){
|
154
|
+
|
155
|
+
var message = $("#msgForm").val();
|
156
|
+
|
157
|
+
$("#msgForm").val('');
|
158
|
+
|
159
|
+
socket.emit("client_to_server", {value : message});
|
160
|
+
|
161
|
+
e.preventDefault();
|
162
|
+
|
163
|
+
});
|
164
|
+
|
165
|
+
</script>
|
166
|
+
|
167
|
+
</body>
|
168
|
+
|
169
|
+
</html>
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
|
174
|
+
|
87
175
|
|
88
176
|
|
89
177
|
### 試したこと
|