Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
mmCAtE #1
Member since Apr 2010 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: InvalidCastException when is use SocketConnectionType.HttpPolling
In C#, cast an object of BASE CLASS to an object of SUB CLASS is not allowed.
e.g. this code:   run it, and error will broken
    class Program
    {
        static void Main(string[] args)
        {
            Program pro = new Program();
            SubProg sub = new SubProg();

            sub = (SubProg)pro;
        }
    }

    class SubProg : Program
    {

    }
But, there are some codes of AGSXMPP SDK is written like that, such as line282 of class agsXMPP.XmppConnection.
protocol.Stream st = (protocol.Stream)e;
Object e is an object of class agsXMPP.Xml.Dom.Node, and st is an object of class agsXMPP.protocol.Stream.

So, I think, maybe that is a BUG?

P.S. I use SocketConnectionType.HttpPolling to connect server with a proxy.
P.S. If my English is not clear, and if you know Chinese, you can visit http://code.google.com/p/ltw/wiki/agsXMPPSDK…?ts=1272254… for the Chinese version.
Avatar
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
this is no bug. agsXMPP is able to cast the base class to the subsclass. This is how it's designed using the factory pattern.

Alex
Avatar
mmCAtE #3
Member since Apr 2010 · 4 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex, but I do not understand something now.
My code is:
XmppClientConnection xmpp = new XmppClientConnection();
xmpp.Server = "http://gmail.com";
xmpp.Username = "username";
xmpp.Password = "password";xmpp.Port = 80;
xmpp.SocketConnectionType = SocketConnectionType.HttpPolling;
PollClientSocket socket = (PollClientSocket)xmpp.ClientSocket;
socket.Proxy = new WebProxy("address", 8080);
xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
xmpp.OnError += new ErrorHandler(xmpp_OnError);
xmpp.OnSocketError += new ErrorHandler(xmpp_OnSocketError);
xmpp.Open();
I try to connect to the gmail server with a proxy, but I just find how to connect it by Socket but not WebRequest.
Is my code correct? Or, I must use factory for this purpose?

P.S. Alex, do you understand my English?
Avatar
Alex #4
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The GTalk servers support no BOSH (HTTP Binding). This is why it does not work for you.

Alex
Avatar
mmCAtE #5
Member since Apr 2010 · 4 posts
Group memberships: Members
Show profile · Link to this post
Oh, that is a probrom.
But, GoogleTalk itself can work with proxy correct, it uses a different way to do this?
Avatar
Alex #6
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
BOSH != Proxy

I don't know what the Google Talk client does when you connect with proxy. agsXMPP does not support proxy for direct XMPP connections. MatriX supports SOCKS4,5 and HTTP Connect.

Alex
Avatar
mmCAtE #7
Member since Apr 2010 · 4 posts
Group memberships: Members
Show profile · Link to this post
Thank you very much for your help, Alex.
I think I may try another way to do this, h~h~
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