Hi there. Sorry for posting this in the wrong forum, I apologise but hope someone can guide me in the right direction.
I have googled for this endlessly however the examples are poor or they are ok but cannot seem to understand them or simply there is not enough in depth explaination.
I want to be able to create a simple application that sends/recieves data.
I will have a Server app which listens to a connection and acts to whatever it needs to do (read data from that conneciton and so on)
Q is, how do I create a socket listener which will keep running until the client says "close connection" or until the application is terminated
I have made an example by following some websites on creating such an app however it will only work once - in other words, it does not continuously keep listening on that connection.
Surely there must be an EVENT that I can inherit or something which is dedicated to keep listening to a connection and recieve data
BTW - this is using VS.NET 2003 with .NET framework 1.1

Sockets
Presanna
Philippe Cherfils
I think I found a way of doing that in .NET 1.1
a Q though - I do not understand how to send data to the client using the new thread created that has been parameterized....
the client in my case is a mobile device (smartphone). It can send data no problem to the server but would also like the server to send data to the mobile device and to enable the mobile device to recieve that data (as well as currently sending data)
Bruce_Daddy
http://www.vgdotnet.com/articles/real_time_vis.shtml
Vincent_D
1 Q though... since the server only recieves, is there a way to make it also send data to an existing client connetion
Mark Toth
as for the user who posted the code - ParameterizedThreadStart does not exist in .NET Framework 1.1 (it's v2.0) - is there an alternative using .NET framework 1.1
Will the client connection still be accepted if they use .NET 1.1 and the Server uses .NET 2.0 Framework
Krolrules
SchallerJe
Daniel J Segan
I'm assuming that you're creating a Stream socket over TCP/IP. If that's the case you can do the following:
void Listen()
{
System.Net.Sockets.TcpListener listener = new TcpListener(6000);
while (true)
{
Socket client = listener.AcceptSocket();
Thread clientThread = new Thread(new ParameterizedThreadStart(ClientThread));
clientThread.Start(client);
}
}
void ClientThread(object param)
{
Socket clientSocket = (Socket)param;
byte[] buffer = new byte[1024];
while (clientSocket.Receive(buffer) > 0)
{
// Do stuff with client socket
}
}
The Listen method loops indefinitely listening for clients. When a client connects, it spawns a separate thread for the client and starts it. All the client communication happens in this thread.
You can modify this to allow only one client at a time.
HTH.