Run the networkstream type in Windows Phone 7.

Source: Internet
Author: User

I wroteArticle: Indicates the socket type of Windows Phone 7. In fact, there are more than the network stream type in Windows Phone 7.

So I manually wrote one, which is very simple, as follows:

> It inherits the stream type and is named networkstream. The namespace must be system. net.

> Create a constructor. Pay attention to the fileaccess parameter in networkstream and set the stream. Canread and canwrite attributes correctly according to the fileaccess parameter.

> Rewrite the stream. Read and Write methods, and use eventwaithandle to synchronize the asynchronous socketasynceventargs operation in Windows Phone 7.

> After the socketasynceventargs. Completed event is executed, a socketexception exception is thrown Based on the socketerror error.

> Pay attention to necessary parameter verification (if necessary, argumentnullexception and argumentoutofrangeexception are thrown. Also, consider the Canread and canwrite attributes ).

> You can use abstract members for rewriting, such as Canread and canwrite. Note that the stream. Flush method does not require any operation.

> Rewrite other unsupported abstract methods and throw the notsupportedexception, such as the canseek attribute and setlength method.

 

CodeThis is a little longer, so you don't need to post it. You can download it:

Source Code download
download page
note: the link is the Microsoft SkyDrive page, when downloading, use a browser to download the file directly. Some download tools may not be able to download the file.
applicable environment: Windows Phone 7/8
test environment: microsoft Visual Studio express 2012 for Windows Phone
file type :. CS file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.