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

T

trint

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(IAsyncResult ar)
{
int BytesRead;
string strMessage;

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

///
// Start a new asynchronous read into readBuffer.
client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new
AsyncCallback(DoRead), null);

ThreadFunction1 thr1 = new ThreadFunction1();
Thread tid1 = new Thread(new ThreadStart(thr1.getOneAtATime ) );
}
catch( Exception e)
{
MarkAsDisconnected();
}
}

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.performclick()"
Help is appreciated.
Thanks,
Trint
 
W

Willy Denoyette [MVP]

trint said:
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(IAsyncResult ar)
{
int BytesRead;
string strMessage;

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

///
// Start a new asynchronous read into readBuffer.
client.GetStream().BeginRead(readBuffer, 0, READ_BUFFER_SIZE, new
AsyncCallback(DoRead), null);

ThreadFunction1 thr1 = new ThreadFunction1();
Thread tid1 = new Thread(new ThreadStart(thr1.getOneAtATime ) );
}
catch( Exception e)
{
MarkAsDisconnected();
}
}

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.performclick()"
Help is appreciated.
Thanks,
Trint

Missing a tid1.Start() ?

Willy.
 
T

trint

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top