我正在尝试从套接字中编写和读取xml,但我不知道如何使用.Net来实现这一点。SocketStream看起来是一种简单的方法,但我并不试图为Windows8或Windows构建一个应用程序。如果有人能够分享一些关于如何使用.Net进行等效操作的洞察力或代码片段,我将非常感激。
private const string MESSAGE_SERVER_URL = "xmpp.messenger.live.com";
private const string MESSAGE_SERVER_PORT = "5222";
/// <summary>
/// login into live message server
/// </summary>
private async void LoginXMPPServer(string access)
{
using (StreamSocket client = new StreamSocket())
{
// connect to server
await client.ConnectAsync(new HostName(MESSAGE_SERVER_URL), MESSAGE_SERVER_PORT);
DataWriter writer = new DataWriter(client.OutputStream);
DataReader reader = new DataReader(client.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
//initialize a stream
string head = "<?xml version='1.0'?>" +
"<stream:stream " +
"to='messenger.live.com' " +
"xmlns='jabber:client' " +
"xmlns:stream='http://etherx.jabber.org/streams' " +
"version='1.0'>";
await SendMessage(head, writer);
string reply = await ReadReplay(reader);
if (reply.Contains("stream:error"))
return;
}
}发布于 2013-11-27 22:14:36
这是一个来自.net SendFile方法的例子
// Establish the local endpoint for the socket.
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);
// Create a TCP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Connect the socket to the remote endpoint.
client.Connect(ipEndPoint);
// There is a text file test.txt located in the root directory.
string fileName = "C:\\test.txt";
// Send file fileName to remote device
Console.WriteLine("Sending {0} to the host.", fileName);
client.SendFile(fileName);
// Release the socket.
client.Shutdown(SocketShutdown.Both);
client.Close();https://stackoverflow.com/questions/20253090
复制相似问题