Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
amol #1
User title: amol
Member since Sep 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Socket connection failure
Hi,

I am using AGSXmpp for some sample program.

If I try to connect to a XMPP server within my LAN, it works fine always.

But if server is outside of LAN on publick-ip, then many times I get following socket-exceptions:
agsXMPP.net.BaseSocket.FireOnError(System.Exception ex = {"Unable to write data to the transport connection: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied."})

This occurs in ClientSocket.cs file in "EndConnect(IAsyncResult ar)" function where it tries to call InitSSL().
So after socket creation,  looks like this is the first place where it tries to send any information over that socket and gets the mentioned error.

Surprisingly, if I try such 2 connection attempts back-to-back ( try second if first fails ) , then the first attempt consistently fails with given
socket exception, and the second attempt always works correctly.

I am not able to understand reason behind it.

The difference between 'in LAN' and 'out side LAN' is the socket-connection may take a bit longer time to happen.

Is this causing any problem ??????
I am using 0.92 version.

Thanks,
Amol
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Amol,

can you please use the latest version 1.0 and come back if it does not solve your problems?

Thanks,
Alex
Avatar
amol #3
User title: amol
Member since Sep 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

Today I tried with agsXMPP 1.0 .
It also gave me the same socket error as mentioned.

One point I missed in my earlier post.
I typically get this error in follwoing case:
I am already connected to xmpp-server. My network connection goes down and my xmpp connection gets closed.
Then I poll for network.
As soon as I find network-available , I make a new xmpp connection and try to connect.
Here...I get the mentioned error.

Thanks,
Amol
Avatar
amol #4
User title: amol
Member since Sep 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Does anyone want to suggest anything ??

Thanks,
Amol
Avatar
Alex #5
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
make sure that you handle all error events.
It looks like you get disconnected and send data after you were disconnected.

Alex
Avatar
Pennidren #6
Member since Oct 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
I ran into a similar thing.
I have reduced my code to a very simple example of the issue.  It seems to have nothing to do with my usage of agsXMPP except that I start a new thread for the call to Open.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

using agsXMPP;
using agsXMPP.protocol.client;

namespace ConsoleApplication1
{
  class Program
  {
    private static XmppClientConnection _Connection = new XmppClientConnection();

    static void Main(string[] args)
    {
      _Connection.Server = "yourserver.com";
      _Connection.Username = "yourusername";
      _Connection.Password = "yourpassword";

      Thread connectThread = new Thread(new ParameterizedThreadStart(ConnectKernel));
      connectThread.Start();

      Console.ReadLine();
    }


    private static void ConnectKernel(object o)
    {
      _Connection.Open();
    }
  }
}

Run this code with a breakpoint on the ClientSocket.Send(byte[]) method at the call to Disconnect() in the exception handler and it will hit and and give the exception being discussed.
If I don't start the connection in a separate thread, it works fine.
Also, and this is odd, if I put a breakpoint on the ClientSocket.Send(byte[]) method at the call to m_NetworkStream.BeginWrite and wait a moment before executing it, it also works fine.  This makes me think it is some threading issue related to the socket, but I can't see what it is.

Help would be most appreciated!
Avatar
Alex #7
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
please look at this thread:
http://forum.ag-software.de/forum.php?req=thread&id=679

and let me know if it fixes your problem.

Alex
Avatar
Pennidren #8
Member since Oct 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
That may help the Disconnect cleanup, but I don't think it addresses the problem in the first place.
Do you see the behavior I described with my sample?
Avatar
Alex #9
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I tried your example and see the same behavior, but I have no idea yet why the exception occurs.
The Socket is connected but for some reason the NetworkStream is not ready for writing data, even if CanWrite is true.

Alex
Avatar
Alex #10
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

I wrote a small socket test project which throws the same exception. I still did not find the problem.
But, I asked several other developers to run the example code and it ran fine without exceptions on the most machines.

Please download the attached code and it on your machine. The "Connect in new Thread" Button throws the exception on some machines.

Alex
The author has attached one file to this post:
SocketTest.zip 14.5 kBytes
You have no permission to open this file.
Avatar
Pennidren #11
Member since Oct 2008 · 3 posts
Group memberships: Members
Show profile · Link to this post
Yes, this throws the exception for me.

Okay, so it isn't consistent.  What do I do, get a new machine?    8-(
Avatar
Alex #12
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
hi Pennidren,

the question is why it fails on your and on my machines. But not on many other machines. I wrote this basic example to get rid of all the agsXMPP dependencies to cause the exception. I spend lots of time on finding the root of the problem, but I see nothing wrong in my code.
So I think the problem is located somewhere in .NET or something I am doing wrong in the code.
I will consult the .NET newsgroups next.

Alex
Avatar
Alex #13
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
FYI,
http://www.microsoft.com/communities/newsgroups/…?dg=mic…

It looks like this is a Framework bug. But I will keep you informed.
As a workaround you have to keep your thread alive. Why are you using a thread at all for your XmppClientConnection? Do you have many simultaneous connections?

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS