473,513 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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

Nov 17 '05 #1
2 1576

"trint" <tr***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.
Nov 17 '05 #2
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
8484
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
1
3378
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
4
18087
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
2
2865
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
7
2366
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew...
13
2632
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
5
4744
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
1
7119
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.