Click here to Skip to main content
15,895,709 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need help with binding source Pin
faizych6-Apr-09 12:34
faizych6-Apr-09 12:34 
GeneralRe: Need help with binding source Pin
Henry Minute7-Apr-09 1:58
Henry Minute7-Apr-09 1:58 
Questionpassing XML data between .NET exes Pin
dyNamite6-Apr-09 8:21
dyNamite6-Apr-09 8:21 
AnswerRe: passing XML data between .NET exes Pin
Jimmanuel6-Apr-09 8:36
Jimmanuel6-Apr-09 8:36 
GeneralRe: passing XML data between .NET exes Pin
dyNamite7-Apr-09 7:12
dyNamite7-Apr-09 7:12 
GeneralRe: passing XML data between .NET exes Pin
Jimmanuel7-Apr-09 12:12
Jimmanuel7-Apr-09 12:12 
GeneralRe: passing XML data between .NET exes Pin
dyNamite8-Apr-09 18:17
dyNamite8-Apr-09 18:17 
QuestionThreading & StreamReader.Read() Question Pin
Harvey Saayman6-Apr-09 7:47
Harvey Saayman6-Apr-09 7:47 
Hey guys

I've been battling to get a response from a server using TcpClient. Now finally after 3 days of problems due to the learning curve I'm getting responses from the server Smile | :)

Here is the code at the moment.

private void ReceiveMessages()
{
    //
    // This method executes in its own thread
    try
    {
        // Get the stream where responses will come from
        srReceiver = new StreamReader(tcpServer.GetStream());

        string result = string.Empty;
        
        while (Connected)
        {
            //
            // Read the next byte and convert it to a char 
            char CurrentChar = (char)srReceiver.Read();

            //
            // if the current character is one of the three Terminators, flag as such
            if (CurrentChar == RecordTerminator)      // 0x00
            {
                result += "[Record Terminator]";
            }
            else if (CurrentChar == FieldTerminator)  // 0x01
            {
                result += "[Field Terminator]";
            }
            else if (CurrentChar == PacketTerminator) // 0x02
            {
                result += "[Packet Terminator]";
            }
            else
            {
                result += CurrentChar.ToString();
            }

            if (#########) // Condition??? :confused:
            {
                //
                // Send the response back to the main thread
                this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { result });

                //
                // Clear the result string
                result = string.Empty;
            }
        }
    }
    catch (Exception ex)
    {
        //
        // Send exception back to the main thread
        this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { ex.Message });
    }
}


Now one of the weirdness's I came across is that if I try StreamReader.ReadLine() I get empty strings as response.
If I use StreamReader.Read() I get the correct response, one character at a time.

Obviously i cant use the CallBack for every character received as this is way to slow, so what I'd like is to only send the use the callback after all the data has been read. But how do i know when its finished? IE what condition do i need to set instead of the #########? Cause if StreamReader.Read() is called and there is no data, it waits for some.

PS, I cant use the packet terminator as this is not always sent at the end of every packet response

Any ideas?

Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL

you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

AnswerRe: Threading & StreamReader.Read() Question Pin
S. Senthil Kumar6-Apr-09 8:09
S. Senthil Kumar6-Apr-09 8:09 
GeneralRe: Threading & StreamReader.Read() Question Pin
Harvey Saayman6-Apr-09 8:51
Harvey Saayman6-Apr-09 8:51 
AnswerRe: Threading & StreamReader.Read() Question Pin
Luc Pattyn6-Apr-09 8:30
sitebuilderLuc Pattyn6-Apr-09 8:30 
Questionhow to transfer binary files ? Pin
E_Gold6-Apr-09 7:05
E_Gold6-Apr-09 7:05 
AnswerRe: how to transfer binary files ? PinPopular
Luc Pattyn6-Apr-09 7:23
sitebuilderLuc Pattyn6-Apr-09 7:23 
GeneralRe: how to transfer binary files ? Pin
EliottA6-Apr-09 9:16
EliottA6-Apr-09 9:16 
GeneralRe: how to transfer binary files ? Pin
Luc Pattyn6-Apr-09 9:34
sitebuilderLuc Pattyn6-Apr-09 9:34 
AnswerRe: how to transfer binary files ? Pin
jschell6-Apr-09 8:16
jschell6-Apr-09 8:16 
AnswerRe: how to transfer binary files ? Pin
riced6-Apr-09 12:06
riced6-Apr-09 12:06 
Questionproblem with listview and an extended treelistView Pin
mirko866-Apr-09 6:34
mirko866-Apr-09 6:34 
AnswerRe: problem with listview and an extended treelistView Pin
DaveyM696-Apr-09 12:04
professionalDaveyM696-Apr-09 12:04 
AnswerRe: problem with listview and an extended treelistView Pin
Mycroft Holmes6-Apr-09 12:24
professionalMycroft Holmes6-Apr-09 12:24 
QuestionCreating Setup File Pin
Narendra Reddy Vajrala6-Apr-09 6:10
Narendra Reddy Vajrala6-Apr-09 6:10 
QuestionRe: Creating Setup File Pin
Eddy Vluggen6-Apr-09 6:17
professionalEddy Vluggen6-Apr-09 6:17 
AnswerRe: Creating Setup File Pin
Narendra Reddy Vajrala6-Apr-09 6:30
Narendra Reddy Vajrala6-Apr-09 6:30 
GeneralRe: Creating Setup File Pin
Rajdeep.NET is BACK6-Apr-09 7:36
Rajdeep.NET is BACK6-Apr-09 7:36 
GeneralRe: Creating Setup File Pin
Narendra Reddy Vajrala6-Apr-09 23:08
Narendra Reddy Vajrala6-Apr-09 23:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.