how to create multiple connections in a client application
-
i have a client application i which i need to connect to the remote machine on click of a button and localhost on every minute.is it possible. plz help me.
Can you be more specific as to how you want to connect to a machine ? Is it a database connection you wish to establish ?
-
i have a client application i which i need to connect to the remote machine on click of a button and localhost on every minute.is it possible. plz help me.
Yes.. On every client request create a new thread and run the task in its own thread until it returns to its tread pool. Just like what IIS does for every requests. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Can you be more specific as to how you want to connect to a machine ? Is it a database connection you wish to establish ?
-
Yes.. On every client request create a new thread and run the task in its own thread until it returns to its tread pool. Just like what IIS does for every requests. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Yes.. On every client request create a new thread and run the task in its own thread until it returns to its tread pool. Just like what IIS does for every requests. :)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>i have tried running threads in this format. but this also works only if button is clicked and only for 4 times but i wish 1 client to connect to the server when button is clicked and other client will connect and close for each minute. the code is:-
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 4; i++)
{
Thread thread = new Thread(new ParameterizedThreadStart(round));
thread.Start();
thread.Join();
Thread.Sleep(100);
}
}
private void round(object val)
{
System.Net.IPAddress myIP;
System.Net.IPEndPoint myServer;
Socket socket;
string ip = (string)val;try { myIP = System.Net.IPAddress.Parse(ip); myServer = new System.Net.IPEndPoint(myIP, Int32.Parse("20000")); socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream ,ProtocolType.Tcp); socket.Connect(myServer); NetworkStream netStream=new NetworkStream(socket); Byte\[\] byteMessage=new Byte\[640\]; string sendMessage="hello server"; byteMessage=System.Text.Encoding.Default.GetBytes( sendMessage.ToCharArray()); netStream.Write(byteMessage,0,byteMessage.Length); netStream.Flush(); netStream.Close(); socket.Close(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }