473,472 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

client server connection check

3 New Member
hii

im developing a client server connection.

i have a set of servers..

and i connect the client to one of these servers using the following code

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.IO;
  3. using System.Net.Sockets;
  4. using System.Diagnostics;
  5. using System.Threading;
  6. using System.Net;
  7.  
  8. class EmployeeTCPClient
  9. {
  10.     public static TcpClient client;
  11.     public static string[] ipsrvr;
  12.     public static int m = 0;
  13.     //public static IPAddress[] ipsrvr;
  14.     [STAThread]
  15.     public static void Main(string[] args)
  16.     {
  17.         ipsrvr = new string[4];
  18.         //ipsrvr = new IPAddress[4];
  19.         ipsrvr[0] = "1.2.3.4";
  20.  
  21.         ipsrvr[1] = "55.6.7.80";
  22.         ipsrvr[2] = "23.45.67.89";
  23.         ipsrvr[3] = "34.56.78.98";
  24.  
  25.         sconnect(ipsrvr[m]);
  26.  
  27.         Console.ReadLine();
  28.  
  29.     }
  30.     public static void sconnect(string id)
  31.     {
  32.  
  33.         client = new TcpClient(id,8080);
  34.  
  35.  
  36.         if (client.Connected)
  37.         {
  38.             Console.WriteLine("Connected to Server");
  39.  
  40.         }
  41.         else
  42.         {
  43.             m++;
  44.             if (m > 3)
  45.             {
  46.                 Console.WriteLine("All servers are down");
  47.             }
  48.             else
  49.             {
  50.                 sconnect(ipsrvr[m]);
  51.             }
  52.  
  53.         }
  54.  
  55.  
  56.     }
the problem is even if all the servers are down. the client.connected returns the value true...it does not go to the else part... and displays Connected to server...y is this happpening.

how to check that the client is connected to server or not.
Mar 17 '08 #1
0 921

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Boris Nikolaevich | last post by:
This is backwards of what I usually want--normally if you have a long-running ASP script, it's a good idea to check to see whether the client is still connected so you can cancel execution. ...
4
by: Mike Dole | last post by:
I'm working on a client - server application based on the 'How to Sockets Server and How to Sockets Client' code from the Visual Basic ..NET Resource Kit. Since I want to be able to send 'big...
2
by: news.microsoft.com | last post by:
Hi I write dll library which one of it component will be Net socket communication. Communication is working very good, but i've got problem when client is connecting. When server is started,...
2
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a...
7
by: rdh | last post by:
Hi all, I am in process of developing a Server in C++ supporting multiple protocols. The server will be exposing various functionalities, and the clients can communicate over any of the...
4
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
8
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
3
by: D. Yates | last post by:
Hi, I'm about to embark on a project that will both send and receive information to/from our client computers in the field. The area that I still need to finalize is the method of...
9
by: timor.super | last post by:
Hi group, I've written a client/server application, using the dotnet sockets. In my server, I have a thread waiting for messages with : ret = currSocket.Receive(buffer, 1024,...
3
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <? function...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.