diff options
Diffstat (limited to 'src/WebSocket.hs')
| -rw-r--r-- | src/WebSocket.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/WebSocket.hs b/src/WebSocket.hs index 0492c81..4179cfa 100644 --- a/src/WebSocket.hs +++ b/src/WebSocket.hs @@ -1,11 +1,13 @@ module WebSocket ( Connection, startClient, + startDefaultWebSocketConnections, sendMessage, receiveMessage, ) where -import Control.Concurrent.Chan +import Control.Concurrent +import Control.Monad import Data.ByteString (ByteString) import Data.ByteString.Unsafe @@ -70,6 +72,15 @@ startClient server addr port path fun = do dropPeerAddress server $ CustomPeerAddress conn +startDefaultWebSocketConnections :: Server -> IO () +startDefaultWebSocketConnections server = do + startClient server "a.discovery.erebosprotocol.net" 443 "" $ \conn -> do + void $ forkIO $ forever $ do + msg <- receiveMessage conn + receivedFromCustomAddress server conn msg + void $ serverPeerCustom server conn + + sendMessage :: Connection -> ByteString -> IO () sendMessage Connection {..} bs = do unsafeUseAsCStringLen bs $ \( ptr, len ) -> do |