Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 与.Net等效的SocketStream_C#_.net_Sockets_Tcp_Xmpp - Fatal编程技术网

C# 与.Net等效的SocketStream

C# 与.Net等效的SocketStream,c#,.net,sockets,tcp,xmpp,C#,.net,Sockets,Tcp,Xmpp,我正在尝试从套接字写入和读取xml,但我不知道如何使用.Net来实现这一点。SocketStream看起来是一种简单的方法,但我不想为Windows 8或Windows phone构建应用程序。如果有人能分享一些关于如何使用.Net实现等效功能的见解或代码片段,我将不胜感激 private const string MESSAGE_SERVER_URL = "xmpp.messenger.live.com"; private const string MESSAG

我正在尝试从套接字写入和读取xml,但我不知道如何使用.Net来实现这一点。SocketStream看起来是一种简单的方法,但我不想为Windows 8或Windows phone构建应用程序。如果有人能分享一些关于如何使用.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;
             }
       }
private const string MESSAGE\u SERVER\u URL=“xmpp.messenger.live.com”;
private const string MESSAGE_SERVER_PORT=“5222”;
/// 
///登录到实时消息服务器
/// 
专用异步void LoginXMPPServer(字符串访问)
{
使用(StreamSocket client=new StreamSocket())
{
//连接到服务器
等待client.ConnectAsync(新主机名(MESSAGE\u SERVER\u URL)、MESSAGE\u SERVER\u端口);
DataWriter writer=新的DataWriter(client.OutputStream);
DataReader=新的DataReader(client.InputStream);
reader.InputStreamOptions=InputStreamOptions.Partial;
//初始化流
字符串头=“”+
"";
等待发送消息(负责人、作者);
字符串回复=等待读取重播(读卡器);
if(reply.Contains(“流:错误”))
返回;
}
}

这是从


我已经编辑了您的问题,并将
[WPF]
标记替换为
[.Net]
标记,因为这实际上与WPF没有任何关系。
// 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();