@@ -16,12 +16,12 @@ class WSConnector:
1616 Event flag is set to *True* when websocket thread is connected to the webserver and **send** can be used.
1717
1818 error : Event
19- Event flag is set to *True* when error accured and connection is closed.
19+ Event flag is set to *True* when error occured and connection is closed.
2020
2121 The flag **error** has a higher priotiy than the **connected** flag. Meaning when **error** is set to *True*, the
2222 connection is closed even when **connected** can be set to *True*.
2323
24- For further invastigation, check developer notes in **on_error**
24+ For further invastigation, check developer notes in `_on_error()`.
2525 """
2626
2727 def __init__ (self , username :str , token :str , address :str ,
@@ -73,10 +73,7 @@ def __init__(self, username:str, token:str, address:str,
7373 if ignore_ssl_cert :
7474 kwargs = None
7575
76- self .timeout = 3
77- if timeout > 0 :
78- self .timeout = timeout
79- setdefaulttimeout (self .timeout )
76+ self .set_timeout (timeout )
8077
8178 self .thread = Thread (target = self .ws .run_forever , kwargs = kwargs )
8279
@@ -90,8 +87,8 @@ def open(self):
9087 After opening the websocket, the websocket thread sets the **connected** event flag to *True* and is ready to
9188 send data.
9289
93- When an error accured upon opening, the **error** flag will be set to *True* and **on_error()** will be called.
94- In this case, the connection will be closed again and the **connected** flag will cleared to *False* again.
90+ When an error occured upon opening, the **error** flag will be set to *True* and `_on_error()` will be called.
91+ In this case, the connection will be closed again and the **connected** flag will be cleared to *False* again.
9592 """
9693 if self .verbosity == VerbosityLevel .ALL :
9794 print ("Opening websocket connection." )
@@ -111,7 +108,7 @@ def open(self):
111108
112109 def send (self , data ):
113110 """
114- Send data via websocket connection.
111+ Sends data via websocket connection.
115112
116113 Raises a *WebSocketConnectionClosedException* when no connection is present.
117114 """
@@ -139,9 +136,9 @@ def send(self, data):
139136
140137 def close (self ):
141138 """
142- Close websocket connection.
139+ Closes websocket connection.
143140
144- This function can still be used when no connection is present.
141+ This function can still be used when no connection is present. In this case, nothing will happen.
145142 """
146143 if self .verbosity == VerbosityLevel .ALL :
147144 print ("Closing connection." )
@@ -163,13 +160,13 @@ def construct_package(self, payload_data):
163160
164161
165162 def set_timeout (self , timeout = 10 ):
166- self .timeout = 3
163+ self .timeout = 2.5
167164 if timeout > 0 :
168165 self .timeout = timeout
169166 setdefaulttimeout (self .timeout )
170167
171168
172- # Functions used by the websocket thread:
169+ ## Functions used by the websocket thread ##
173170
174171 def _on_open (self , ws : WebSocketApp ):
175172 """
@@ -197,12 +194,12 @@ def _on_close(self, ws: WebSocketApp, close_status_code, close_msg):
197194 ----------------
198195 Developer notes:
199196
200- When the websocket thread has been started, **on_close** will always be called, even when an error accured upon
201- opening the connection. This is a result of the ** teardown()** function in WebSocketApp.
197+ When the websocket thread has been started, `_on_close()` will always be called, even when an error occured upon
198+ opening the connection. This is a result of the ` teardown()` function in WebSocketApp.
202199
203- So its possible that **on_close()** will be called even when **on_open()** hasn't been called yet.
200+ So its possible that `_on_close()` will be called even when `_on_open()` hasn't been called yet.
204201
205- For further invastigation, check the developer notes in **on_error()** .
202+ For further invastigation, check the developer notes in `_on_error()` .
206203 """
207204 if self .verbosity == VerbosityLevel .ALL :
208205 print ("Connection closed." )
@@ -216,23 +213,23 @@ def _on_error(self, ws: WebSocketApp, err: Exception):
216213
217214 This function will save the **exception** and set the flag **error** to *True*.
218215
219- This function also sets the flag **connected** to *True* to avoid blocking of **open** when an error accured
216+ This function also sets the flag **connected** to *True* to avoid blocking of **open** when an error occured
220217 upon opening the connection.
221218
222219 ----------------
223220 Developer notes:
224221
225- This method is used by WebSocketApp as callback function. The intend is to signal that an error accured in
222+ This method is used by WebSocketApp as callback function. The intend is to signal that an error occured in
226223 WebSocketApp and to allow further error handeling outside of WebSocketApp.
227224
228- Because we use ** run_forever()** without a parameter for ** reconnect()** , we use the standard of *0* from the
225+ Because we use ` run_forever()` without a parameter for ` reconnect()` , we use the standard of *0* from the
229226 websocket-client library. This will always force a teardown of the connection without an attempt to reconnect
230227 upon error.
231228
232- A teardown of the connection will also call the ** _on_close()** callback function, even when ** _on_error()**
233- has been the called. ** _on_close()** will even be called when an error accured on the attempt to open the
229+ A teardown of the connection will also call the ` _on_close()` callback function, even when ` _on_error()`
230+ has been the called. ` _on_close()` will even be called when an error occured on the attempt to open the
234231 websocket.
235- Meaning, ** _on_close()** can be called even when ** _on_open()** hasn't been called yet.
232+ Meaning, ` _on_close()` can be called even when ` _on_open()` hasn't been called yet.
236233
237234 Do not raise an exception here!
238235 --------------------------------
0 commit comments