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