Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open Lwt.Infix
- (* a list associating user nicknames to the output channels that write to their connections *)
- (* Once we fix the other functions this should change to []*)
- let sessions = ref [("",Lwt_io.null)]
- exception Quit
- (* replace Lwt.return below with code that uses Lwt_list.iter_p to
- print sender: msg on each output channel (excluding the sender's)*)
- let rec send_all sender msg = Lwt.return ()
- (* remove a session from the list of sessions: important so we don't try to
- write to a closed connection *)
- let remove_session nn =
- sessions := List.remove_assoc nn !sessions;
- send_all nn "<left chat>" >>= fun () ->
- Lwt.return ()
- (* Modify to handle the "Quit" case separately, closing the channels before removing the session *)
- let handle_error e nn inp outp = remove_session nn
- (* modify sessions to remove (nn,outp) association, add (new_nn,outp) association.
- also notify other participants of new nickname *)
- let change_nn nn outp new_nn = Lwt.return ()
- (* + obtain initial nick(name),
- + add (nick,outp) to !sessions, and
- + announce join to other users *)
- let handle_login nr (inp,outp) =
- Lwt_io.printl "Enter initial nick:" >>= fun () -> Lwt.return ();;
- (* modify handle_input below to detect /q, /n, and /l commands *)
- let handle_input nr outp l = send_all !nr l
- let chat_server _ (inp,outp) =
- let nick = ref "" in
- (* replace () below with call to handle_login *)
- let _ = handle_login nick (inp,outp) in
- let rec main_loop () =
- Lwt_io.read_line inp >>= handle_input nick outp >>= main_loop in
- Lwt.catch main_loop (fun e -> handle_error e !nick inp outp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement