5 Replies - 382 Views - Last Post: 31 July 2013 - 06:31 PM Rate Topic: -----

#1 ROSE2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-July 13

How do I create multiple clients from one client program?

Posted 31 July 2013 - 12:36 AM

What I'm trying to do is transform a shared memory system program into a distributed system, using sockets and multiple clients. I have read quite a few articles and instructions on how to create servers and clients. Most of theses focus just on how to handle a single client. I have found a few websites on how to somewhat handle the server part of my program, but I'm trying to create a client program that creates multiple threads of that client, instead of me having to create separate client programs, because essentially all the clients would work the same, and run concurrently. Also how would these clients communicate with each other, is through the server itself?

Wanted to also know how would I terminate each client after a certain runtime, is that what the wait() and sleep() function for?

Any advice, hints, or links to lead me in the right direction of fixing my problems is greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I create multiple clients from one client program?

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3457
  • View blog
  • Posts: 10,664
  • Joined: 05-May 12

Re: How do I create multiple clients from one client program?

Posted 31 July 2013 - 05:44 AM

If you are going to host multiple clients in a single client program through the use of threading, and the clients are just supposed to interact with each other, why even bother creating a server? Just continue to use shared memory between the threads of your client program. It gets even easier because you don't even have to explicitly setup shared memory between the threads. The memory is naturally shared.

If your really want to use sockets and go client-server, the trick is to change your server code to accept multiple connections. You are going the wrong path with going with multiple threads within the single client program.
Was This Post Helpful? 0
  • +
  • -

#3 ROSE2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-July 13

Re: How do I create multiple clients from one client program?

Posted 31 July 2013 - 05:59 AM

Well the purpose is to have the clients act as if they are running on separate machines. The problem is I need the clients to connect at the same time. I have had trouble in the past with make files, so I don't even know if that would work.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3457
  • View blog
  • Posts: 10,664
  • Joined: 05-May 12

Re: How do I create multiple clients from one client program?

Posted 31 July 2013 - 06:10 AM

View PostROSE2, on 31 July 2013 - 08:59 AM, said:

I have had trouble in the past with make files, so I don't even know if that would work.

Makefile's should have no impact on how your program works with multiple threads or going client-server. You could as easily compile the same program with a shell script or just re-type everything every time.

View PostROSE2, on 31 July 2013 - 08:59 AM, said:

Well the purpose is to have the clients act as if they are running on separate machines. The problem is I need the clients to connect at the same time.

Well you aren't going to get that effect of having multiple clients from separate machines because they will all be coming from the same source machine if you have multiple threads.

If you don't care if it's the same machine, then just open multiple shell windows and run your client from each of the shells. If the client is a GUI, simply run multiple instances of the client program (assuming that your GUI code doesn't have anything the forces only a single instance that can be run per session).
Was This Post Helpful? 0
  • +
  • -

#5 ROSE2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-July 13

Re: How do I create multiple clients from one client program?

Posted 31 July 2013 - 08:26 AM

Okay so if I run multiple instances of a client, how do I distiguish between the different clients. Would I handle that in the server.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3457
  • View blog
  • Posts: 10,664
  • Joined: 05-May 12

Re: How do I create multiple clients from one client program?

Posted 31 July 2013 - 06:31 PM

Yes, you would handle keeping track of each connection on the server. As for the identity of each client, it really depends on what you need to accomplish. You could take the strategy that each client has a distinct and unique identity to simulate unique persons logging in; or you could assign ids as you accept connections; or you could not care at all and just base everything on the connection handle that you get as you accept each connection.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1