The problem I'm having is when I try to read the file it only reads the filename. What is necessary to read the contents of the file.
I have trying using the Binarywritter to first write the file locallly but I can't seem to make it as I'm getting the data from Packet.RequestLoadFile
Not for example "BinaryReader b = new BinaryReader(File.Open("some file name", FileMode.Open)). How do I make it so the file can get saved locally first? or there is another way to read the Packet.RequestLoadFile?
The following code came from another thread
http://www.tasharen.com/forum/index.php?topic=9165.0I have added the code for function OnLoadFile(). I try using the different kinds of 'reads' (char, chars...) but is only reads the filename not the contents from the file.
I think I'm getting close to the solution please help.
public class LoadGame : MonoBehaviour {
void Start()
{
TNManager.SetPacketHandler(Packet.ResponseLoadFile, OnLoadFile);
}
void OnLoadFile (Packet response, BinaryReader reader, IPEndPoint source)
{
using (BinaryReader b = reader)
{
// Position and length variables.
int pos = 0;
// Use BaseStream.
int length = (int)b.BaseStream.Length;
while (pos < length)
{
// Read...
string v = b.ReadString();
Debug.Log(v.ToString());
// Advance our position variable.
}
}
}
public void LoadFile (string filename)
{
BinaryWriter writer = TNManager.BeginSend(Packet.RequestLoadFile);
writer.Write(filename);
TNManager.EndSend();
}
}