How to share an address using StreamSocket?

我只是一个虾纸丫 提交于 2019-12-25 11:57:35

问题


I'm able to pass a text, and it works like a charm!

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

It shows the link in the other device's browser.


回答1:


Pseudo code:

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);


来源:https://stackoverflow.com/questions/27363527/how-to-share-an-address-using-streamsocket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!