TAILIEUCHUNG - Professional Microsoft Smartphone Programming phần 5

Trong đoạn mã ví dụ trên, bạn có thể sử dụng hoặc các nhà xây dựng mặc định, hoặc chấp nhận một tham số chuỗi (người dùng định nghĩa ngoại lệ: không hợp lệ Zip Code), hoặc chấp nhận các tham số chuỗi và một trường hợp ngoại lệ (mới ArgumentException () ). Ví dụ, hai cuộc gọi sau đây ném cũng có thể được sử dụng trong ví dụ trên: | Chapter 7 Thread t new Thread new ThreadStart 200 catch SocketException ex private void WorkerThreadProc TcpClient client null NetworkStream ns null try int size 0 int buffer_len 1024 byte buffer new byte buffer_len Message to the client string hello Ping From Server r n byte res hello int res_len The server blocks here waiting for a client client Here comes a client ns Send our Ping message res 0 res_len Receive Pong message from the client while size buffer 0 buffer_len 0 data buffer 0 size Update UI using the delegate method new InvokeDelegate InvokeMethod catch SocketException ex catch lOException ex finally 186 Networking This method will run in the context of the UI thread Don t place network processing code here because it will block UI update private void InvokeMethod Connected to a client r n data This example doesn t use an additional UI update thread in the TcpClient because its operations are not sophisticated you don t need to update the UI while waiting for the server s response. If you have some more controls on the UI and would allow the user to access the controls while the TcpClient blocks for the server s response you need to place the TcpClient-related tasks into a thread other than the main UI thread the form thread . Network Sockets The TcpListener class does not provide all the socket-level functionality such as socket options socket polling and selection. If a pluggable protocol requires more flexible control over network connections on the socket level a TcpListener does not suffice. For this purpose you can use the . class which implements the Berkeley socket interface. .

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.