TAILIEUCHUNG - Foundations of F#.Net phần 9

Tham khảo tài liệu 'foundations of f#.net phần 9', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 246 CHAPTER 10 DISTRIBUTED APPLICATIONS open open open let form let temp new Form - F Talk Client fun e - 0 let output new TextBox Dock ReadOnly true Multiline true output let input new TextBox Dock Multiline true input let tc new TcpClient localhost 4242 let load let run let sr new StreamReader while true do let text if text null text then new MethodInvoker fun - text - ignore let t new Thread new ThreadStart run fun _ - load let sw new StreamWriter let keyUp _ if 1 then let text if text null text then CHAPTER 10 DISTRIBUTED APPLICATIONS 247 begin try text with err - sprintf Server error n n O err ignore end - fun _ - keyUp e temp STAThread do form Figure 10-1 shows the resulting client-server application. Figure 10-1. The chat client-server application Now you ll look at how the client in Listing 10-2 works. The first portion of code in the client is taken up initializing various aspects of the form this is not of interest to you at the moment though you can find details of how WinForms applications work in Chapter 8. The first part of Listing 10-2 that is relevant to TCP IP sockets programming is when you connect to the server. You do this by creating a new instance of the TcpClient class and calling its Connect method 248 CHAPTER 10 DISTRIBUTED APPLICATIONS let tc new TcpClient localhost 4242 In this example you specify localhost which is the local computer and port 4242 which is the same port on which the server is listening. In a more realistic example you d probably give the DNS name of the server

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.