LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2004, 08:39 PM   #1
AquamaN
Member
 
Registered: Oct 2002
Location: Ohio, USA
Distribution: OS X 10.4.8, Ubuntu 6.10
Posts: 146

Rep: Reputation: 15
client/server multiplexing


Ok, can anyone give me any ideas on how to implement this program correctly. I need to basically do a client / server relationship. I use the gsl library to generate customers randomly, then after that I need a "server", which is just an if statement, to service the customer for the specified amount of time. I just am unsure of how to do this.

Code:
#include <stdio.h>
#include <iostream.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <vector>


int main (int argc, char *argv[])
{
	const gsl_rng_type * T;
	gsl_rng * r;
	float N, R, alpha, M;
	int closeTime;

	cout<<"N:  ";  // number of lines
	cin>>N;
	cout<<"R:  ";  // rate of entry
	cin>>R;
	cout<<"alpha:  ";  //amount of bsy time  
	cin>>alpha;
	cout<<"M:  ";  // output capacity
	cin>>M;
	cout<<"closeTime:  ";
	cin>>closeTime;

	double mu = N * R * alpha;   // arrival rate (N, R and alpha)   
	int maxSize = (int)mu * closeTime;
	float S = 1/M;
	float waitList[maxSize], customerList[maxSize], server[1];
 

	gsl_rng_env_setup();

	T = gsl_rng_default;
	r = gsl_rng_alloc (T);

  
	int counter = 0;
	float arrivalTime = 0;
	double expRandom = gsl_ran_exponential (r, 1/mu);
	arrivalTime = arrivalTime + expRandom;
	server[0] = 0;
	float serviceTime;
	int custDone = 0;
	float currentTime = 0.00;
	
	while(1)
	{

		if(currentTime > arrivalTime) //maybe use rate?
		{
			expRandom = gsl_ran_exponential (r, 1/mu);
			arrivalTime = arrivalTime + expRandom;
			if(server[0] == 0)
			{
				server[0] = arrivalTime;
				cout << "Customer arrived at: " << arrivalTime << " and put into service." << endl;
			}
			else
			{
				waitList[counter] = arrivalTime;
				counter++;
				cout << "Customer arrived at: " << arrivalTime << " and put into queue." << endl;
			}

		}

		//serviceTime = arrivalTime + S;

		if(server[0] != 0)
		{
			cout << "Customer: " << server[0] << " is being served." << endl;
			
			

			if(counter > 0 && custDone == 1)
			{
				server[0] = waitList[0];
				for(int x = 0; x < counter; x++)
					waitList[x] = waitList[x + 1];
			}
		}
   
		currentTime += 1;

	}

  return 0;
}
 
Old 03-25-2004, 04:44 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
What's unclear? For me, the code is nearly good.
IMHO you shouldn't currentTime+=1. I'd make currentTime minimum of arrivalTime and the time the server will finish with the client.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is a multiplexing server good for? Thinking Programming 4 08-10-2005 02:39 PM
Bandwidth multiplexing russell Linux - Networking 3 04-14-2005 07:11 PM
Multiplexing ADSLs ? michaelsanford Linux - Networking 6 04-14-2005 05:51 PM
can not connect to my pureftp server from Linux client, but i can from windows client bonito SUSE / openSUSE 5 03-16-2005 09:45 PM
Refresh client user list at autentication client/server network. robertoneto123 Linux - Networking 0 11-11-2003 10:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration