Lander
Lander
CC#
Created by Lander on 12/31/2022 in #help
✅ Recieve less than transmitting in network stream
Hello there, I'm trying to implement a FTP server and I got troubles with the network stream Whenever I transmit a 4669 file, I recieve only 3779 and it's sending 0 which as it says marks the end of the data. The headers I sent indicate the file's size so I know exactly how much to expect and I got the conditions for it. I have tried almost everything I could think of. Here is the code for the server:
while(totalRead < size)
{
read = reader.Read(buffer, 0, buffer.Length);
if (read == 0)
{
Console.WriteLine("read is empty {0}", read);
break;
}


totalRead += read;
if(read < buffer.Length)
{
Array.Resize(ref buffer, read);
}
f.Write(buffer,0, buffer.Length);
f.Seek(totalRead, SeekOrigin.Begin);
}
reader.Close();
while(totalRead < size)
{
read = reader.Read(buffer, 0, buffer.Length);
if (read == 0)
{
Console.WriteLine("read is empty {0}", read);
break;
}


totalRead += read;
if(read < buffer.Length)
{
Array.Resize(ref buffer, read);
}
f.Write(buffer,0, buffer.Length);
f.Seek(totalRead, SeekOrigin.Begin);
}
reader.Close();
Here is the code of the client:
while (totalRead < fSz)
{
read = fs.Read(buf, 0, buf.Length);
if (read == 0)
break;
totalRead += read;
if(read < buf.Length)
{
Array.Resize(ref buf, read);
}

stream.Write(buf, 0, buf.Length);

}
fs.Close();

stream.Close();
while (totalRead < fSz)
{
read = fs.Read(buf, 0, buf.Length);
if (read == 0)
break;
totalRead += read;
if(read < buf.Length)
{
Array.Resize(ref buf, read);
}

stream.Write(buf, 0, buf.Length);

}
fs.Close();

stream.Close();
in both
stream
stream
is an instace of Network stream created with the underlying socket of TcpClient. I would appreciate any help. Thank you.
4 replies
CC#
Created by Lander on 12/29/2022 in #help
❔ Winforms one window app with navigation between windows
Hello there, I'm trying to implement a one window winforms app with navigation between the various forms using a dictionary and abit of manipulation with Dispose and Application.Run() Here is a snippet of the running loop code
while (navigatedForm != "quitting")
{
switch (navigatedForm)
{
case "LoginForm":
allForms[navigatedForm] = new LoginForm();
break;
case "RegisterForm":
allForms[navigatedForm] = new RegisterForm();
break;
//case "EmailVerificationForm":
// allForms[navigatedForm] = new EmailVerificationForm();
// break;
case "MainMenuForm":
allForms[navigatedForm] = new MainMenuForm();
break;


default:
break;
}

try
{
Application.Run(allForms[navigatedForm]);
}
catch (Exception ex)
{

DisplayTestWindow(ex.Message, ex.Source, 1);

}
Application.Exit();

}
while (navigatedForm != "quitting")
{
switch (navigatedForm)
{
case "LoginForm":
allForms[navigatedForm] = new LoginForm();
break;
case "RegisterForm":
allForms[navigatedForm] = new RegisterForm();
break;
//case "EmailVerificationForm":
// allForms[navigatedForm] = new EmailVerificationForm();
// break;
case "MainMenuForm":
allForms[navigatedForm] = new MainMenuForm();
break;


default:
break;
}

try
{
Application.Run(allForms[navigatedForm]);
}
catch (Exception ex)
{

DisplayTestWindow(ex.Message, ex.Source, 1);

}
Application.Exit();

}
In each form when the user goes to the next, I call Dispose(). In terms of memory, when I tested going back and forth on 2 forms, the Task Manager shown that the memory didn't significantly bypassed the 30-50 MB threshold and at one point dropped to the starting 18 MB. My question is, Is this way hacky and unsafe or it's fine?
2 replies
CC#
Created by Lander on 12/24/2022 in #help
❔ logs with network file sending
Hello there, I'm currently in the process of writing a FTP server and I want to implement a logging system to ensure that both parties are in conisistent state. I know there is the method SendFile() but looking at the documention, doesn't show much beyond simply calling. Is there another function which gives takes abit of load off or the only solution will be to manually send the bytes and log it myself? Thank you.
4 replies
CC#
Created by Lander on 12/18/2022 in #help
❔ Autoresetevent
Hello there, does the state of the Set() method of the object persists until another thread performs a WaitOne() on it? Like if it happens that a manager thread do a Set() and the worker thread didn't arrive to the WaitOne() yet, will the state persist until the worker thread arrive and change the state?
8 replies