Im probably doing something thats obviously wrong, but I dont know which class to make the changes in.
I call a coroutine:
ReadXMLClass.cs
void Awake () {
StartCoroutine("fncGetXMLData");
}
the IEnum function reads in some XML and then inits a download:
ReadXMLClass.cs
IEnumerator fncGetXMLData(){
//Init XML read
//Read XML Code...
//Begin File Download
FTPManager ftplib = new FTPManager();
ftplib.Connect("ftp.ftp.com",21,"username","password");
while(ftplib.DoDownload() > 0)
{
int perc = (int)(((ftplib.BytesTotal) * 100) / ftplib.FileSize);
string strProgress;
strProgress = string.Format("\rDownloading: {0}/{1} {2}%", ftplib.BytesTotal, ftplib.FileSize, perc);
Debug.Log(strProgress);
}
}
I have another large script which is an FTP manager that i use to connect and download stuff into Unity - problem is, whenever i connect or download, the engine is frozen until the request completes:
FTPManager.cs
//Connect function example...
public int Connect()
{
if (server == null)
throw new Exception("No server has been set.");
if (user == null)
throw new Exception("No username has been set.");
if (main_sock != null)
if (main_sock.Connected)
return -1;
main_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
main_ipEndPoint = new IPEndPoint(Dns.GetHostByName(server).AddressList[0], port);
try
{
main_sock.Connect(main_ipEndPoint);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
ReadResponse();
if (response != 220)
Fail();
SendCommand("USER " + user);
ReadResponse();
switch(response)
{
case 331:
if (pass == null)
{
Disconnect();
throw new Exception("No password has been set.");
}
SendCommand("PASS " + pass);
ReadResponse();
if (response != 230)
Fail();
break;
case 230:
break;
}
return 1;
}
I initially thought yield could be an answer, but I dont have control over .NET FTP function after I call it. I thought invoking a new thread could work, but I’m not 100% sure about how that works with Unity - which is why im posting
Also - Reading the XML works fine (no lock while requesting data), as I’m using the built-in WWW in Unity- but Im assuming other .Net components are not aware of of Unity and thus lock until complete.
Cheers
Shaun