Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Maui #1
Member since Sep 2007 · 9 posts · Location: Aachen
Group memberships: Members
Show profile · Link to this post
Subject: Porting JEP65Socket to NET CF 2.0
Hello there,

first, let me thank you for opensourc'ing such a nice SDK which is also usable within the
contrained NET CF enviroment. I've been looking around for such a library for a while  :cool:

As my client development for WM5 continues I am now trying to port JEP65Socket to Windows Mobile.
There is no such thing as Monitor.Wait(), Monitor.Pulse() or System.Timers, so we have to find a way around
these requirements.

I was able to replace these functions with Components from the SDF 2.1 (formerly known as OpenNETCF) but
it seems my Threads are now looping/hanging/waiting for ever (will say: it doesn't work yet)

Could you give me a clue how to restructure JEP65Socket to make it usable with NET CF?

Greetings from Aachen,

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

we used the OpenNetCF Framework in several projects in the past and had no problems.
I think the code you need is in the MonitorEx class.
But you can also get the same behaviour with the AutoResetEvent class.

Alex
Avatar
Alex #3
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
what you can also do is:

  1. while(!some_Flag)
  2. {  
  3.    Thread.Sleep(100);
  4. }

this is more a hack, but works.

Alex
Avatar
Maui #4
Member since Sep 2007 · 9 posts · Location: Aachen
Group memberships: Members
Show profile · Link to this post
Ok, that should be a replacement for Monitor.Wait(),

but how do I replace Monitor.Pulse(), just toggle some_Flag?
I will also have a look at AutoResetEvent.

MonitorEx has been replaced with Monitor2 but as said before, I wasn't able to get it to work

Maui
Avatar
Alex #5
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by Maui:
...
but how do I replace Monitor.Pulse(), just toggle some_Flag?
yes


MonitorEx has been replaced with Monitor2 but as said before, I wasn't able to get it to work
This is weird because is worked for us before. I can take a look if we have some older version of OpenNetCf here.

Alex
Avatar
Maui #6
Member since Sep 2007 · 9 posts · Location: Aachen
Group memberships: Members
Show profile · Link to this post
I copied my changed JEP65Socket.cs to http://www.pastebin.org/2270

Maybe it dosn't work because I had to  modify SendFile() because _socket.BeginFileSend() doesn't exist in NETCF.

        public void SendFile(string filename)
        {
            //_socket.BeginSendFile(filename, new AsyncCallback(OnFileSend), null);
            FileStream myFileStream;
            myFileStream = new FileStream(filename,FileMode.Open,FileAccess. Read,FileShare.Read);//
            byte[] b = new byte[myFileStream.Length];//create a byte array to store
            for(long i=0;i<myFileStream.Length;i++)
            {
                b[i] = (byte)myFileStream.ReadByte();
            }
            myFileStream.Close();

            _socket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnFileSend), null);
        }

        private void OnFileSend(IAsyncResult ar)
        {
            //_socket.EndSendFile(ar);
            _socket.EndSend(ar);
        }

Maui
Avatar
Maui #7
Member since Sep 2007 · 9 posts · Location: Aachen
Group memberships: Members
Show profile · Link to this post
I got a little bit further, I am now able to initiate and recieve file transfer requests.
However it seems after initialisation there is no actual transport.

Debug from Recipient (MiniClient)
RECV: <iq xmlns="jabber:client" from="sebastian.mauer@jabber.rwth-aachen.de/ctp" to="sebastian.mauer@jabber.rwth-aachen.de/4wret" type="set" id="agsXMPP_16"><si xmlns="http://jabber.org/protocol/si" profile="http://jabber.org/protocol/si/profile/file-transfer" id="714039da-e362-4b58-836c-ca386a115d11"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" size="1580" name="Besprechungsnotizen.pwi"><desc>sebastian.mauer@jabber.rwth-aachen.de/4wret</desc><range /></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field type="list-single" var="stream-method"><option><value>http://jabber.org/protocol/bytestreams</value></option></field></x></feature></si></iq>

SEND: <iq xmlns="jabber:client" id="agsXMPP_16" to="sebastian.mauer@jabber.rwth-aachen.de/ctp" type="result"><si xmlns="http://jabber.org/protocol/si" id="714039da-e362-4b58-836c-ca386a115d11"><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field var="stream-method"><value>http://jabber.org/protocol/bytestreams</value></field></x></feature></si></iq>

RECV: <iq xmlns="jabber:client" from="sebastian.mauer@jabber.rwth-aachen.de/ctp" to="sebastian.mauer@jabber.rwth-aachen.de/4wret" type="set" id="agsXMPP_17"><query xmlns="http://jabber.org/protocol/bytestreams" sid="714039da-e362-4b58-836c-ca386a115d11"><streamhost port="7777" jid="proxy.jabber.rwth-aachen.de" host="proxy.jabber.rwth-aachen.de" /></query></iq>

SEND: <iq xmlns="jabber:client" type="result" to="sebastian.mauer@jabber.rwth-aachen.de/ctp" id="agsXMPP_17"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost-used jid="proxy.jabber.rwth-aachen.de" /></query></iq>
Avatar
Alex #8
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The Begin..... functions are for asynchronous communication. We prefer async communication whenever its possible.
Not aa async methods are available on the CF, so you have to use the synchronous members here.

The Xml Log looks Ok so far. After the streamhostused message both clients have to connect to the bytestream proxy and start the transfer.

Alex
Avatar
Maui #9
Member since Sep 2007 · 9 posts · Location: Aachen
Group memberships: Members
Show profile · Link to this post
Hey Alex,
thanks for all your help so far. I hope I'll be able to finish Filetransfer from/to my WM5 Client.

It seems in CF2 there are all necessary Async Operations, however it seems I can not really user OpenNETCF.Timers.Timer2 as replacement, as Timer support is plattform dependant and not even supported by my testing device (XDA mini S)

Currently, not even the direct transfer works as expected.

       private void SendFile(IAsyncResult ar)
        {
            const int BUFFERSIZE = 1024;
            byte[] buffer = new byte[BUFFERSIZE];
            FileStream fs;
            // AsyncResult is null when we call this function the 1st time
            if (ar == null)
            {
                m_startDateTime = DateTime.Now;
                fs = new FileStream(m_FileName, FileMode.Open);
            }
            else
            {

                if (_p2pSocks5Socket.Socket.Connected)
                    _p2pSocks5Socket.Socket.EndReceive(ar); <--------------- IAsyncResult doesn't return

Can you give me a    small sample on howto replace Async Connection with their synchronous Pendants?

maui
Avatar
Alex #10
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
All async socket stuff which you need is also included in the compact framework.
You have to call EndReceive After a packet is received. You are using it wrong.

Take a look at our code how we use it. There are also many examples in the MSDN help.
Our ClientSocket.cs is also a good example.

Alex
Avatar
Maui #11
Member since Sep 2007 · 9 posts · Location: Aachen
Group memberships: Members
Show profile · Link to this post
Ok, i got it working ;)

But I have one last mysterious question. What exactly is the purpose of the Listen()
function within JEP65Socket.cs from the MiniClient example. I had to comment it out because
it would always give me an "incorrect proxy version" error.
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