Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ok so iv made a sort of remote command operator. it is made of 2 sections the server and the client the client sends a command the server executes it and returns the output.

now for some resone i cant read all of the output i can only read a few lines then it just waits for the time out.

i send the output of the command like so "[CommandName:PID]:OneLineOfOutput\n" and then this repeats for each line that the command outputed

and then i try to read this line by line and when there isnt something to read i time out the reading process and wait for a new command to send to the server.

the kind of stuff its ment to output looks like this
[ListCmds:1232]:ListCmds:0
[ListCmds:1232]:Shutdown:1
[ListCmds:1232]:FullSysShutdown:2
[ListCmds:1232]:Restart:3

and this is what i see on the console
[ListCmds:1232]:ListCmds:0
[ListCmds:1232]:Shutdown:1

it just seems to skip 2 lines.

my reading thread code
private static void ReturnManager(Socket Soc)
    {
        //Thread.Sleep(100);
        using (StreamReader RS = new StreamReader(new NetworkStream(Soc)))
        {
            DateTime TMR = DateTime.Now;
            while (true)
            {
                if (RS.Peek() > 0)
                {
                    Console.WriteLine(RS.ReadLine());
                    TMR = DateTime.Now;
                }
                if (!Soc.Connected)
                {
                    break;
                }
                if (DateTime.Now - TMR > TimeSpan.FromSeconds(LastReadTimeoutSeconds))
                {
                    break;
                }
                Thread.Sleep(20);
            }
        }
        Soc.Close();
        Soc.Dispose();
    }

now before you ask i did make sure all the data was beeing sent throu the socket on the serer side its just not beeing fully read by the client.

What I have tried:

i have tryed adding a wait timer to the start but that doesnt fix the problem it just makes it harder to happen.
Posted
Updated 11-Feb-18 0:10am

1 solution

I think you should not use StreamReader, see example here:
NetworkStream.Read Method (Byte[], Int32, Int32) (System.Net.Sockets)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900