Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Roger #1
Member since Mar 2011 · 8 posts
Group memberships: Members
Show profile · Link to this post
Subject: problems with receiving files, please help!
Hi Alex,
While sending files works fine, it seems I got stuck with receiving them.

Here's my code based on the MiniClient.

    public partial class Form1 : Form
    {

        private string sid = "";
        private bool haveResponseOnFileIn;

        FileTransferManager fmout = new FileTransferManager(); //// this FileTransferManager is for outgoing files
        FileTransferManager fmin = new FileTransferManager();  //// this FileTransferManager is for incomeing files
        FileTransferEventArgs fta = new FileTransferEventArgs();
        Jid _jid = new Jid();


        public Form1()
        {
            InitializeComponent();

            fmout.OnError += fmout_OnError;
            fmout.OnEnd += fmout_OnEnd;
            fmout.OnStart += fmout_OnStart;
            fmout.OnProgress += fmout_OnProgress;

            fmout.XmppClient = xmppClient;
            fmin.XmppClient = xmppClient;
           

            fmin.OnFile += fmin_OnFile;
            fmin.OnEnd += fmin_OnEnd;
            fmin.OnStart += fmin_OnStart;
            fmin.OnProgress += fmin_OnProgress;
        }

        ////////////////////////////////////////////////////////////////////////////////////////////

        public void StartAccept()
        {
            while (!haveResponseOnFileIn)
            {
                Thread.Sleep(100);
                Application.DoEvents();
                DisplayEvent("x");          //////// this looping works... but what is it for?
            }
        }



        void fmin_OnFile(object sender, FileTransferEventArgs e)
        {

            fta = e;

            DisplayEvent("INCOMING FILE: " + fta.Filename + " - " + fta.FileSize);

            StartAccept();              ////// WHAT DO WE NEED THIS LOOP FOR?

            fta.Accept = true;             /////// LOOKS AS IF THIS DOES NOT LAUNCH fmin_OnStart ... shouldn't it?
            haveResponseOnFileIn = true;
           
            //var sf = new SaveFileDialog();
            //if (sf.ShowDialog() == DialogResult.OK) { fta.Directory = Path.GetDirectoryName(sf.FileName); }
        }




        void fmin_OnStart(object sender, FileTransferEventArgs e) /// THIS WON'T START! :(
        {
            MessageBox.Show("In!");
            if (e.Sid != fta.Sid)
                return;
        }




        void fmin_OnProgress(object sender, FileTransferEventArgs e)
        {
            if (e.Sid != fta.Sid)
                return;

            progressBar1.Value = (int)(((double)e.BytesTransmitted / (double)e.FileSize) * 100);
        }



        void fmin_OnEnd(object sender, FileTransferEventArgs e)
        {
            if (e.Sid != fta.Sid)
                return;

            MessageBox.Show("file transfer ended with success!", "Success, YellowBox", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }




      
        //////////////////////////////////////////////////////////////////////////////////////////////////

        private void btn_pickFile_Click(object sender, System.EventArgs e)
        {
            var of = new OpenFileDialog();
            if (of.ShowDialog() == DialogResult.OK)
            {
                tb_file.Text = of.FileName;
                btn_sendFile.Enabled = true;
            }
        }

        private void btn_sendFile_Click(object sender, System.EventArgs e)
        {
            _jid.Server = "qip.ru";
            _jid.User = "274138362";
            _jid.Resource = "MatriX";
            //_jid.Resource = "QIP";

            // Convert.ToString(cb_users.SelectedItem);

            sid = fmout.Send(_jid, tb_file.Text, "myFile");
        }


        void fmout_OnError(object sender, ExceptionEventArgs e)
        {
            var ex = e.Exception as FileTransferException;
            if (ex.Sid != sid)
                return;
            MessageBox.Show("file transfer failed!", "Failure, YellowBox", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        void fmout_OnEnd(object sender, FileTransferEventArgs e)
        {
            if (e.Sid != sid)
                return;
            MessageBox.Show("file transfer ended with success!", "Success, YellowBox", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        void fmout_OnStart(object sender, FileTransferEventArgs e)
        {
            if (e.Sid != sid)
                return;
        }

        void fmout_OnProgress(object sender, FileTransferEventArgs e)
        {
            if (e.Sid != sid)
                return;

            progressBar1.Value = (int)(((double)e.BytesTransmitted / (double)e.FileSize) * 100);
        }

......................


The problem is that fta.Accept = true; won't launch fmin_OnStart ... what do you think might be the problem?

Thanks! :)
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
did you try to send and receive files with 2 MiniClients? This should work.

The loop is only a quick hack which you can do much better in your app ;-)

In the OnFile event you have to return in the EventArgs whether you accept or deny the file transfer request (e.Accept).
In the MiniClient example I pass the EventArgs to FrmReceiveFileForm and have to block the OnFile event until you press Accept or Deny in the form which is done in the loop.
I though a loop is easier to read than some complex thread synchronization code.

Alex
Avatar
Roger #3
Member since Mar 2011 · 8 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the explanation! :)
Now I see what the loop is here for. Since I want to accept files by default, I didn't use it.
Yes, 2 MiniClients work file in sending files to one another.

edit: GOT IT WORKING! :)Appears it just didn't like that I had 2 FileTransferManagers. :)

Thanks!
This post was edited 2 times, last on 2011-03-12, 12:11 by Roger.
Avatar
Roger #4
Member since Mar 2011 · 8 posts
Group memberships: Members
Show profile · Link to this post
Oh, and one more thing. Filetransfer seems extremely slow, 1mb picture could transfer up to 5-10 minutes.
If I understand right, its a direct user-to-user transfer, not user-server-user ?
Avatar
Alex #5
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the FileTransferManager currently supports only IBB which is splitting the file in chunks and sends them through the server in the XMPP stream. When this is slow then your server slows down your connection.
I am working in SOCKS5 bytestreams currently which can be used peer to peer and will be in one of the next updates. But most users on the Internet are firewalled, which means that in most cases you will not be able to establish a peer to peer session with SOCKS5 bytereams.

see also:
SOCKS5: http://xmpp.org/extensions/xep-0065.html
IBB: http://xmpp.org/extensions/xep-0047.html

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: MatriX RSS