Click here to Skip to main content
15,912,069 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends I need help in coding..

Actually I am developing application for making call by soft phones.

In this i have fours ports means at a time i can make four calls.

Here I will get contacts number from webservices those numbers i need to put in Queue then have to check that 4 ports any atleast one port is free or not.. If free then one contact number have to pick from queue and make to dail again that keep on checking that amoung four ports any one port free then pass another number from queue.


Like this queue must be always watching that ports are free or not... if free then pass number from queue.

"Here after call ended automatically am changing port availability otherwise ports are busy like this status wil be keep on changing.. According to the status that queue must pass numbers....

Still not clear na Frown | :( .......

Trying to explain as much as possible you guys....

Sample code:
C#
// code in Form load
ThreadStart ts = new ThreadStart(severgetdata);
Thread serverthread = new Thread(ts);
Thread CurrentThread = serverthread;
serverthread.Start();

// Above lines starting thread.

// servergetdata()

// In this method am getting numbers which i have to dailed... Here for example am using socket layer. By telnet am sending contact number which i have to dailed

public void severgetdata()
{
   byte[] bytes = new Byte[1048576];

   // Establish the local endpoint for the socket.
   // Dns.GetHostName returns the name of the 
   // host running the application.
   IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
   IPAddress ipAddress = ipHostInfo.AddressList[0];
   IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

   // Create a TCP/IP socket.
   Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);

   // Bind the socket to the local endpoint and 
   // listen for incoming connections.
   try
   {
      listener.Bind(localEndPoint);
      listener.Listen(10);

      // Start listening for connections.
      while (true)
      {
         Console.WriteLine("Waiting for a connection...");
         // Program is suspended while waiting for an incoming connection.
         Socket handler = listener.Accept();
         data = null;

         // An incoming connection needs to be processed.
         while (true)
         {
            int bytesRec = handler.Receive(bytes);
            data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
            if (data.IndexOf("") > -1)
            {
               break;
            }
         }

         // Show the data on the console.
         Console.WriteLine("Text received : {0}", data);

         // Echo the data back to the client.
         byte[] msg = Encoding.ASCII.GetBytes(data);
         handler.Send(msg);
         string receivedata = data;

         receivedata = receivedata.Remove(receivedata);

         //After getting contact numbers then am trying to put in Queue.
         QueueCustomers(receivedata);

         Checkports();
         MakeCall();

         handler.Shutdown(SocketShutdown.Both);
         handler.Close();
      }
   }

   catch (Exception e)
   {
      Console.WriteLine(e.ToString());
   }

   Console.WriteLine("\nPress ENTER to continue...");
   Console.Read();
}

// Here I am sending the numbers to Queue like this. after adding in queue then have to check the ports are free or not in CheckPorts() method

public void QueueCustomers(string receivedata)
{
   callCustomer.contactnumber = receivedata;
   CustomerQueue.Enqueue(callCustomer);
   int count = CustomerQueue.Count;
}


Public void Checkports()
{

   // Here am checking ports free or not.
   // if ports available then go for makecall otherwise wait until port get free.

   //ports status will be 1) free---> at initial stage
   // 2) available--> after getting free stage port then change it to available
   // 3) busy----> once call is connected

   // After call ended then states of port wil be changed to free.

   // So whenever the port is free then one number must be come from that queue.....

}

I added sample code here please go through it. I am planning like this to handle. Like this the queue must work on ports states.. I dont know how to make a queue continues to check the ports status.....

Thanks & Regards
S Chand Basha
Posted
Updated 1-Oct-14 1:18am
v3
Comments
Sergey Alexandrovich Kryukov 30-Sep-14 1:55am    
Not clear. What is that, "run" queue? Monitor what?
—SA
BillWoodruff 30-Sep-14 2:03am    
What is the source of the event that triggers action on the queue ? What does "outside" mean when you say "pass from outside."

Is the code that uses the queue always monitoring something: like a folder for a file-change ?

Do you need to raise an event when the queue is modified ?

Show your code.
Sinisa Hajnal 30-Sep-14 2:17am    
Just posting to get info on update. Sounds interesting, if unclear. :)
syed shanu 30-Sep-14 2:22am    
I think you need some thing like this for example you can create Windows form and add one timer in form always run the timer. You can read the input from Text file,XML,CMD parameter or from Database or as you wish.In timer tick you need to check always for the input and once you receive the Input do call your another function and do your action after you finish the task clear the Input data .In timer check for next Input and its routine task.You can run this program on your server as background process.
Sinisa Hajnal 30-Sep-14 2:27am    
If the input is file that comes from remote location (copied or otherwise trasferred) there are FileWatcher components that are easy to configure and program. But Chand Basha did not specify where his input is coming from.

1 solution

As i see your challenge i would suggestion you to choose one of three options.
1. Oldschool MSMQ will survive across machine reboots with elements in queue and is definitively the safest way and it has existed for ages: http://msdn.microsoft.com/en-us/library/ms978430.aspx[^]
2. Make a Web API controller, which will act on any submission also, like you wished Introduction to ASP.NET Web API[^]
3. Do a full blown WCF service http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900