1498
|
1 |
module Main where
|
|
2 |
|
|
3 |
import IO
|
|
4 |
import System.IO
|
|
5 |
import Control.Concurrent
|
|
6 |
import Network
|
|
7 |
import Control.Exception
|
|
8 |
import Control.Monad
|
|
9 |
import System.Random
|
|
10 |
|
|
11 |
session1 nick room = ["NICK", nick, "", "PROTO", "20", "", "CREATE", room, "", "CHAT_STRING", "Hi", ""]
|
|
12 |
session2 nick room = ["NICK", nick, "", "PROTO", "20", "", "JOIN", room, "", "CHAT_STRING", "Hello", ""]
|
|
13 |
|
|
14 |
emulateSession sock s = do
|
|
15 |
mapM_ (\x -> hPutStrLn sock x >> randomRIO (70000::Int, 120000) >>= threadDelay) s
|
|
16 |
hFlush sock
|
|
17 |
threadDelay 250000
|
|
18 |
|
|
19 |
testing = Control.Exception.handle (\e -> putStrLn $ show e) $ do
|
|
20 |
putStrLn "Start"
|
|
21 |
sock <- connectTo "127.0.0.1" (PortNumber 46631)
|
|
22 |
|
|
23 |
num1 <- randomRIO (70000::Int, 70100)
|
|
24 |
num2 <- randomRIO (70000::Int, 70100)
|
|
25 |
num3 <- randomRIO (0::Int, 7)
|
|
26 |
num4 <- randomRIO (0::Int, 7)
|
|
27 |
let nick1 = show $ num1
|
|
28 |
let nick2 = show $ num2
|
|
29 |
let room1 = show $ num3
|
|
30 |
let room2 = show $ num4
|
|
31 |
emulateSession sock $ session1 nick1 room1
|
|
32 |
emulateSession sock $ session2 nick2 room2
|
|
33 |
emulateSession sock $ session2 nick1 room1
|
|
34 |
hClose sock
|
|
35 |
putStrLn "Finish"
|
|
36 |
|
|
37 |
forks = forever $ do
|
|
38 |
delay <- randomRIO (40000::Int, 70000)
|
|
39 |
threadDelay delay
|
|
40 |
forkIO testing
|
|
41 |
|
|
42 |
main = withSocketsDo $ do
|
|
43 |
forks |