Simple C # Metro StreamSocket Example

I am posting this because I already wasted one day searching and programming for what really should be easy to set up even in Metro.

I am looking for an example of a C # StreamSocket that can connect to a socket, read data from a socket (I don’t know exactly when the data will arrive, so I always want to listen to new data) and write data to it at arbitrary times. It was an easy task to execute in every language programming environment (including .NET), but I cannot do it in Metro without getting exceptions ( ObjectDisposedExceptions when trying to write while waiting for incoming data).

These Metro examples are too simple because they know exactly when to poll the data. This simple task should really be possible!

+4
source share
1 answer

If you configured the DataReader to an incoming StreamSocket, you can set its InputStreamOptions to InputStreamOptions.Partial. This will allow you to read the data as it becomes available and dynamically decide how to process it.

 var dr = new DataReader(socket.InputStream); dr.InputStreamOptions = InputStreamOptions.Partial; var stringHeader = await dr.LoadAsync(512); 

This post also mentions http://babaandthepigman.wordpress.com/2012/04/07/streamsocket-example-c-metro/

+1
source

Source: https://habr.com/ru/post/1401550/


All Articles