TAILIEUCHUNG - Programming C#, 2nd Edition

Trong một số cách, cách tiếp cận để tuần tự thể hiện trong Ví dụ 21-15 là rất lãng phí. Bởi vì bạn có thể tính toán các nội dung của mảng số bắt đầu và kết thúc của nó, có thực sự là không có lý do để lưu trữ các phần tử của nó vào đĩa. Mặc dù các hoạt động có thể được không tốn kém với một mảng nhỏ, nó có thể trở nên tốn kém với một trong rất lớn. | Programming C 2nd Edition if bytesRead 0 write it out to the client buffer 0 bytesRead callbackWrite null If OnFileCompletedRead was called and no bytes were read this signifies that the entire file has been sent. The server reacts by closing the NetworkStream and socket thus letting the client know that the transaction is complete networkStream null socket null When the network write completes the OnWriteComplete method is called and this kicks off another read from the file private void OnWriteComplete IAsyncResult ar ar Write complete buffer holds the results 0 offset BufferSize myFileCallBack call back delegate null local state object The cycle begins again with another read of the file and the cycle continues until the file has been completely read and transmitted to the client. The client code simply writes a filename to the network stream to kick off the file read string message @ C test source writer new streamToServer message The client then begins a loop reading from the network stream until no bytes are sent by the server. When the server is done the network stream is closed. Start by initializing a Boolean value to false and creating a buffer to hold the bytes sent by the server bool fQuit false while fQuit char buffer new char BufferSize You are now ready to create a new StreamReader from the NetworkStream member variable streamToServer reader new streamToServer 526 Programming C 2nd Edition The call to Read takes three parameters the buffer the offset at which to begin reading and the size of the buffer int bytesRead buffer 0 Buffersize Check to see if the Read returned any bytes if not you are done and you can set the Boolean value fQuit to true causing the loop to terminate if .

TỪ KHÓA LIÊN QUAN
Đã 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.