I want connect with my jabber server and read server answer:
DnsEndPoint host = new DnsEndPoint("talk.google.com", 5222);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
public void start()
{
string message = "<?xml version=1.0?><stream:streamto='gmail.com'xmlns='jabber:client'xmlns:stream='http://etherx.jabber.org/streams'version='1.0'>";
var buffer = Encoding.UTF8.GetBytes(message);
args.RemoteEndPoint = host;
args.Completed += SocketAsyncEventArgs_Completed;
args.SetBuffer(buffer, 0, buffer.Length);
bool completesAsynchronously = socket.ConnectAsync(args);
if (!completesAsynchronously)
{
SocketAsyncEventArgs_Completed(args.ConnectSocket, args);
}
}
private void SocketAsyncEventArgs_Completed(object sender, SocketAsyncEventArgs e)
{
if (e.SocketError != SocketError.Success)
{
Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show("Error during socket operation: " + e.SocketError));
return;
}
byte[] buffer = e.Buffer;
XDocument temp = ConvertByteArrayToXml(buffer);
}
XDocument ConvertByteArrayToXml(byte[] data)
{
XmlReaderSettings settings = new XmlReaderSettings();
using (MemoryStream stream = new MemoryStream(data))
using (XmlReader reader = XmlReader.Create(stream, settings))
{
return XDocument.Load(reader);
}
}
At Return XDocument.Load(reader)
I get exeption '1.0' is an unexpected token. The expected token is '"' or '''
. How can solve it?
Why I want it? Because when I authorize myself and change status it not affect it at my account.