Skip to content

Commit d0ab6c4

Browse files
committed
Remove redundant method header and fix indent
1 parent fcb623c commit d0ab6c4

File tree

2 files changed

+54
-55
lines changed

2 files changed

+54
-55
lines changed

examples/WebSocketClientSockJsAndStomp/WebSocketClientSockJsAndStomp.ino

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* WebSocketClientSockJsAndStomp.ino
3-
*
4-
* Example for connecting and maintining a connection with a SockJS+STOMP websocket connection.
5-
* In this example we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html).
6-
*
7-
* Created on: 18.07.2017
8-
* Author: Martin Becker <mgbckr>, Contact: [email protected]
9-
*/
2+
WebSocketClientSockJsAndStomp.ino
3+
4+
Example for connecting and maintining a connection with a SockJS+STOMP websocket connection.
5+
In this example we connect to a Spring application (see https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html).
6+
7+
Created on: 18.07.2017
8+
Author: Martin Becker <mgbckr>, Contact: [email protected]
9+
*/
1010

1111
// PRE
1212

@@ -28,7 +28,7 @@ const char* ws_host = "the.host.net";
2828
const int ws_port = 80;
2929

3030
// base URL for SockJS (websocket) connection
31-
// The complete URL will look something like this(cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36):
31+
// The complete URL will look something like this(cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36):
3232
// ws://<ws_host>:<ws_port>/<ws_baseurl>/<3digits>/<randomstring>/websocket
3333
// For the default config of Spring's SockJS/STOMP support the default base URL is "/socketentry/".
3434
const char* ws_baseurl = "/socketentry/"; // don't forget leading and trailing "/" !!!
@@ -43,7 +43,7 @@ WebSocketsClient webSocket;
4343

4444
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
4545

46-
switch(type) {
46+
switch (type) {
4747
case WStype_DISCONNECTED:
4848
USE_SERIAL.printf("[WSc] Disconnected!\n");
4949
break;
@@ -52,43 +52,43 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
5252
USE_SERIAL.printf("[WSc] Connected to url: %s\n", payload);
5353
}
5454
break;
55-
case WStype_TEXT: {
56-
57-
// #####################
58-
// handle STOMP protocol
59-
// #####################
60-
61-
String text = (char*) payload;
62-
63-
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
64-
65-
if (payload[0] == 'h') {
66-
67-
USE_SERIAL.println("Heartbeat!");
68-
69-
} else if (payload[0] == 'o') {
70-
71-
// on open connection
72-
char *msg = "[\"CONNECT\\naccept-version:1.1,1.0\\nheart-beat:10000,10000\\n\\n\\u0000\"]";
73-
webSocket.sendTXT(msg);
74-
75-
} else if (text.startsWith("a[\"CONNECTED")) {
76-
77-
// subscribe to some channels
78-
79-
char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]";
80-
webSocket.sendTXT(msg);
81-
delay(1000);
82-
83-
// and send a message
84-
85-
msg = "[\"SEND\\ndestination:/app/message\\n\\n{\\\"user\\\":\\\"esp\\\",\\\"message\\\":\\\"Hello!\\\"}\\u0000\"]";
86-
webSocket.sendTXT(msg);
87-
delay(1000);
88-
}
55+
case WStype_TEXT:
56+
{
57+
// #####################
58+
// handle STOMP protocol
59+
// #####################
8960

90-
break;
91-
}
61+
String text = (char*) payload;
62+
63+
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
64+
65+
if (payload[0] == 'h') {
66+
67+
USE_SERIAL.println("Heartbeat!");
68+
69+
} else if (payload[0] == 'o') {
70+
71+
// on open connection
72+
char *msg = "[\"CONNECT\\naccept-version:1.1,1.0\\nheart-beat:10000,10000\\n\\n\\u0000\"]";
73+
webSocket.sendTXT(msg);
74+
75+
} else if (text.startsWith("a[\"CONNECTED")) {
76+
77+
// subscribe to some channels
78+
79+
char *msg = "[\"SUBSCRIBE\\nid:sub-0\\ndestination:/user/queue/messages\\n\\n\\u0000\"]";
80+
webSocket.sendTXT(msg);
81+
delay(1000);
82+
83+
// and send a message
84+
85+
msg = "[\"SEND\\ndestination:/app/message\\n\\n{\\\"user\\\":\\\"esp\\\",\\\"message\\\":\\\"Hello!\\\"}\\u0000\"]";
86+
webSocket.sendTXT(msg);
87+
delay(1000);
88+
}
89+
90+
break;
91+
}
9292
case WStype_BIN:
9393
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
9494
hexdump(payload, length);
@@ -107,7 +107,7 @@ void setup() {
107107
// USE_SERIAL.begin(921600);
108108
USE_SERIAL.begin(115200);
109109

110-
// USE_SERIAL.setDebugOutput(true);
110+
// USE_SERIAL.setDebugOutput(true);
111111

112112
USE_SERIAL.println();
113113

@@ -117,28 +117,28 @@ void setup() {
117117
USE_SERIAL.print("Logging into WLAN: "); Serial.print(wlan_ssid); Serial.print(" ...");
118118
WiFi.mode(WIFI_STA);
119119
WiFi.begin(wlan_ssid, wlan_password);
120-
120+
121121
while (WiFi.status() != WL_CONNECTED) {
122-
delay(500);
123-
USE_SERIAL.print(".");
122+
delay(500);
123+
USE_SERIAL.print(".");
124124
}
125125
USE_SERIAL.println(" success.");
126126
USE_SERIAL.print("IP: "); USE_SERIAL.println(WiFi.localIP());
127127

128-
128+
129129
// #####################
130130
// create socket url according to SockJS protocol (cf. http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-36)
131131
// #####################
132132
String socketUrl = ws_baseurl;
133-
socketUrl += random(0,999);
133+
socketUrl += random(0, 999);
134134
socketUrl += "/";
135-
socketUrl += random(0,999999); // should be a random string, but this works (see )
135+
socketUrl += random(0, 999999); // should be a random string, but this works (see )
136136
socketUrl += "/websocket";
137137

138138
// connect to websocket
139139
webSocket.begin(ws_host, ws_port, socketUrl);
140140
webSocket.setExtraHeaders(); // remove "Origin: file://" header because it breaks the connection with Spring's default websocket config
141-
// webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny
141+
// webSocket.setExtraHeaders("foo: I am so funny\r\nbar: not"); // some headers, in case you feel funny
142142
webSocket.onEvent(webSocketEvent);
143143
}
144144

src/WebSocketsClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class WebSocketsClient: private WebSockets {
8282
void setAuthorization(const char * auth);
8383

8484
void setExtraHeaders(const char * extraHeaders = NULL);
85-
void setExtraHeaders(char * extraHeaders);
8685

8786
protected:
8887
String _host;

0 commit comments

Comments
 (0)