簡體   English   中英

如何使用StreamSocket共享地址?

[英]How to share an address using StreamSocket?

我能夠傳遞文本,並且它就像一種魅力!

StreamSocketListener streamSocketListener = new StreamSocketListener();
streamSocketListener.ConnectionReceived += streamSocketListener_ConnectionReceived;
await streamSocketListener.BindEndpointAsync(hostName, port);

它在另一台設備的瀏覽器中顯示鏈接。

偽代碼:

IStorageFile fileToSend = await KnownFolders.PicturesLibrary.GetFileAsync("foo.jpg");
BasicProperties basicProperties = await fileToSend.GetBasicPropertiesAsync();
IInputStream streamToSend = await fileToSend.OpenReadAsync();

string headers = "HTTP/1.1 OK 200\r\n" +
    "Content-Length:" + basicProperties.Size + "\r\n" +
    "Content-Type: " + fileToSend.ContentType + "\r\n" +
    "Connection: Keep-Alive\r\n\r\n";

writer.WriteString(stringToSend);
await writer.StoreAsync();
writer.DetachStream();

await RandomAccessStream.CopyAndCloseAsync(streamToSend, socket.OutputStream);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM