Socket Server to Socket Client..Client function not working when called from Server...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • trint

    Socket Server to Socket Client..Client function not working when called from Server...

    I have an app that uses the standard Socket Client code. I send it a
    message to call a function and it receives the message, debugs through
    the function, but the function doesn't actually fire. Anyone have a
    clue? Here is the code:

    public void DoRead(IAsyncRe sult ar)
    {
    int BytesRead;
    string strMessage;

    try
    {
    // Finish asynchronous read into readBuffer and return number of
    bytes read.
    BytesRead = client.GetStrea m().EndRead(ar) ;
    if (BytesRead < 1)
    {
    // if no bytes were read server has close. Disable input window.
    MarkAsDisconnec ted();
    return;
    }
    // Convert the byte array the message was saved into, minus two for
    the
    // Chr(13) and Chr(10)
    strMessage = Encoding.ASCII. GetString(readB uffer, 0, BytesRead -
    2);
    ProcessCommands (strMessage);
    ///

    ///
    // Start a new asynchronous read into readBuffer.
    client.GetStrea m().BeginRead(r eadBuffer, 0, READ_BUFFER_SIZ E, new
    AsyncCallback(D oRead), null);

    ThreadFunction1 thr1 = new ThreadFunction1 ();
    Thread tid1 = new Thread(new ThreadStart(thr 1.getOneAtATime ) );
    }
    catch( Exception e)
    {
    MarkAsDisconnec ted();
    }
    }

    the function that I need to run is getOneAtATime. The function works
    with a button click...but will not work outside this thread, inside
    this thread or even if i call the button click "button.perform click()"
    Help is appreciated.
    Thanks,
    Trint

  • Willy Denoyette [MVP]

    #2
    Re: Socket Server to Socket Client..Client function not working when called from Server...


    "trint" <trinity.smith@ gmail.com> wrote in message
    news:1113422991 .606098.156330@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    >I have an app that uses the standard Socket Client code. I send it a
    > message to call a function and it receives the message, debugs through
    > the function, but the function doesn't actually fire. Anyone have a
    > clue? Here is the code:
    >
    > public void DoRead(IAsyncRe sult ar)
    > {
    > int BytesRead;
    > string strMessage;
    >
    > try
    > {
    > // Finish asynchronous read into readBuffer and return number of
    > bytes read.
    > BytesRead = client.GetStrea m().EndRead(ar) ;
    > if (BytesRead < 1)
    > {
    > // if no bytes were read server has close. Disable input window.
    > MarkAsDisconnec ted();
    > return;
    > }
    > // Convert the byte array the message was saved into, minus two for
    > the
    > // Chr(13) and Chr(10)
    > strMessage = Encoding.ASCII. GetString(readB uffer, 0, BytesRead -
    > 2);
    > ProcessCommands (strMessage);
    > ///
    >
    > ///
    > // Start a new asynchronous read into readBuffer.
    > client.GetStrea m().BeginRead(r eadBuffer, 0, READ_BUFFER_SIZ E, new
    > AsyncCallback(D oRead), null);
    >
    > ThreadFunction1 thr1 = new ThreadFunction1 ();
    > Thread tid1 = new Thread(new ThreadStart(thr 1.getOneAtATime ) );
    > }
    > catch( Exception e)
    > {
    > MarkAsDisconnec ted();
    > }
    > }
    >
    > the function that I need to run is getOneAtATime. The function works
    > with a button click...but will not work outside this thread, inside
    > this thread or even if i call the button click "button.perform click()"
    > Help is appreciated.
    > Thanks,
    > Trint
    >[/color]

    Missing a tid1.Start() ?

    Willy.


    Comment

    • trint

      #3
      Re: Socket Server to Socket Client..Client function not working when called from Server...

      Willy,
      You are correct...but after I fixed that, it still didn't execute
      although the debugger steps through the function. Even if it isn't in
      a thread, it doesn't work. It works when "button_clicked ". Or any
      other direct event to the Client program except a read from the server.
      This phenomenon happens "or doesn't happen" when attempting to execute
      it from the Socket Server:

      Socket Server (message to client) ----tcp/ip-----> Socket Client
      (message received) "nothing".

      Thanks,
      Trint

      Comment

      Working...