简体   繁体   中英

Can multiple ClientSocket Components can be placed on a Form?

I am looking to write a program that will connect to many computers from a single computer. Sort of like "Command Center" where you can monitor all the remote system remotely on a single PC.

My plan is to have multiple Client Sockets on a form. They will connect to individual PCs remotely. So, they can request information from them to display on the Window. Remote PCs will be hosts. Is this possible?

Direct answer to your question: Yes, you can do that.

Long answer: Yes, you can do that but are you sure your design is correct? Are you sure you want to create parallel connections, one to each client ? Probably you don't! If yes, then you probably want to run them in separate threads.

If you want to send some commands from time to time (and you are not doing some kind of constant video monitoring) why don't you just use one connection and 'switch' between clients?

I can't tell you more about the design because from your question is not clear about what you want to build (what exactly you are 'monitoring').

VERY IMPORTANT!

Two important notices to take into account before designing your app (both relevants only if the remote computers are not in the LAN (you connect to them via Internet)):

  1. If the remote computers are running as servers, you will have lots of problems to explain your customers (if they are connected (and they probably are) to Internet via a router) how to setup the router and the software firewall. For example, if a remote computer is listening for commands from you, on port 1234 (for example) the firewall in the router will block BY DEFAULT any connection attempt from a 'foreign' computer (from you) to that port.
  2. If your remote computers are running as clients, how they will know master's IP (your IP). Do you have a static IP?

What you actually need is one ServerSocket on the module running on your machine. To which all your remote PC's will connect through their individual ClientSocket.

You can make your design other way round by putting ClientSocket on the module running on your machine and ServerSocket on the module running on remote machine.

But you will end up creating one ClientSocket to each ServerSocket, what if you have the number of remote servers increase.

Now if you still want to have multiple ClientSockets on your machine then as Altar said you could need a multi threaded application where each thread is responsible for one ClientSocket.

I would recommend Internet Direct (Indy) as they work well in threads, and you can specify a connect time-out per connection, so that your monitoring app will be able to get a 'negative' test result faster than with the default OS connect time-out.

Instead of placing them on the form, I would wrap each client in a class which runs an internal monitoring thread. More work initially but easier to keep independent from each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM