File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,6 +169,14 @@ def test_closing_message_received(self):
169169 ws .process (b'unused for this test' )
170170 c .assert_called_once_with (1000 , b'test closing' )
171171
172+ def test_sending_ping (self ):
173+ tm = PingControlMessage ("hello" ).single (mask = False )
174+
175+ m = MagicMock ()
176+ ws = WebSocket (sock = m )
177+ ws .ping ("hello" )
178+ m .sendall .assert_called_once_with (tm )
179+
172180
173181if __name__ == '__main__' :
174182 suite = unittest .TestSuite ()
Original file line number Diff line number Diff line change 88from ws4py import WS_KEY , WS_VERSION
99from ws4py .exc import HandshakeError , StreamClosed
1010from ws4py .streaming import Stream
11- from ws4py .messaging import Message , PongControlMessage
11+ from ws4py .messaging import Message , PingControlMessage ,\
12+ PongControlMessage
1213from ws4py .compat import basestring , unicode
1314
1415DEFAULT_READING_SIZE = 2
@@ -210,6 +211,13 @@ def close_connection(self):
210211 finally :
211212 self .sock = None
212213
214+ def ping (self , message ):
215+ """
216+ Send a ping message to the remote peer.
217+ The given `message` must be a unicode string.
218+ """
219+ self .send (PingControlMessage (message ))
220+
213221 def ponged (self , pong ):
214222 """
215223 Pong message, as a :class:`messaging.PongControlMessage` instance,
You can’t perform that action at this time.
0 commit comments