Hi. I have a VoIP modem and I connect it to my family's computer. The program that I use which serves as a server is YAC (Yet Another Caller ID). In my laptop, since I used Ethereal to listen to the caller ID info, here's an example text:
Test Call ~(425) 555-1212
As I look at the code:
TcpListener server=null; try { // Set the TcpListener on port 13000. Int32 port = 13000; IPAddress localAddr = IPAddress.Parse("127.0.0.1"); // TcpListener server = new TcpListener(port); server = new TcpListener(localAddr, port);
// Start listening for client requests. server.Start(); // Buffer for reading data Byte[] bytes = new Byte[256]; String data = null;
// Enter the listening loop. while(true) { Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Connected!");
data = null;
// Get a stream object for reading and writing NetworkStream stream = client.GetStream();
int i;
// Loop to receive all the data sent by the client. while((i = stream.Read(bytes, 0, bytes.Length))!=0) { // Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); Console.WriteLine("Received: {0}", data); // Process the data sent by the client. data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
// Send back a response. stream.Write(msg, 0, msg.Length); Console.WriteLine("Sent: {0}", data); } // Shutdown and end connection client.Close(); } } catch(SocketException e) { Console.WriteLine("SocketException: {0}", e); } finally { // Stop listening for new clients. server.Stop(); }
Console.WriteLine("\nHit enter to continue..."); Console.Read();
I noticed that it only listens to specific IP address but I wanted a program to listen to any IP address (well, private IP address but it doeesn't have to be a Class C Private IP Address, notably 192.168.x.x). So when I detect the packet with Caller ID information, I can be able to extract the caller name and caller phone number. Plus, since the TTY (teletypewriter; used for the deaf/hearing imparied) can't be audible (it only flashes a light), I can be able to play an audio file to let me know that I got a phone call, without purchasing a phone alerter that makes sound when TTY phone rings, which I'll do coding by my own.
Off-topic: For those who want to question me about using my TTY over VoIP (Vonage, which I'm currently using with Comcast), I have the cable modem first, Motorola VT2142 phone adapter second that connects to cable modem, and router third which connects to my phone adapter. I get very clear signal without any garbled text. The TTY, along with my phone adapter and router are downstairs, whereas my laptop are located upstairs, so since I use my laptop all the time, I can't be able to know who calls me, but even though I have downloaded YAC (remember the link that I've provided ) and run a YAC Listener, it doesn't have the ability to play audio files to let me know, so it will be great if I could help detect the packet that I wanted to get when getting caller ID information and that I don't have to miss a phone call. The router that I have is D-Link DI-524.
.NET Development20
|