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!
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!