Making YAC Send Caller ID Information to Listeners
Before you start coding in Java, you must set up your YAC Server to send socket messages containing caller ID information. The YAC Server can send messages to the machine it resides on (i.e., the server) or to different machines in your network (i.e., clients). In either case, you have to register the clients/listeners YAC will send caller ID information to. To do this, right click on the YAC icon in your task notification area and select the Listeners… option (see
Figure 3).
 | |
| Figure 3. Choosing the Listeners Context Menu Option |
In the subsequent Select listeners window, specify the hostname or IP address of the machines in your network that you want to process caller ID information. If you just want to process caller ID information on the server itself, just enter the IP address of your YAC server machine and click OK (see Figure 4).
Using the YAC Software Developer’s Kit
The
YAC Software Developer’s Kit shows how you can create a YAC listener that can consume caller ID information sent by the YAC server to registered IP addresses (as done in the previous step section). YAC listeners listen on TCP port 10629 by default (a configurable option).
The YAC Software Developer’s Kit specifies that a client should listen for an incoming connection and then copy all sent text into a buffer until it receives either a null character (i.e., ‘\O’) or 300 characters. The listener should then close the connection and do whatever it desires with the caller ID information it received.
The YAC Software Developer’s Kit specifies a typical caller ID buffer as follows:
@CALLBush George W.~(212) 555-9384\0
 | |
| Figure 4. Specifying YAC Listener Connection Information |
With this information, you are now ready to start coding a Java client that will listen for caller ID information as reported via a YAC server.
Creating a Java (Socket) Listener
You can find the code for your Java-based YAC Listener in the class
YACListener.java. The first thing to do in the code is create a java.net.ServerSocket, which is bound to the YAC port, 10629:
ServerSocket serverSocket = new ServerSocket(port);
Next, in a while loop, listen for an incoming connection to the socket and accept it with the line:
Socket socket = serverSocket.accept();
Consume the data the YAC server sends with the syntax below, which grabs an input stream for the socket and binds it to a BufferedReader object:
BufferedReader input =
new BufferedReader(new InputStreamReader(socket.getInputStream()));
To report your caller ID payload to your client, use another while loop, which listens and breaks if your input is null and outputs to the console if it isn't:
// print received callerID data
while (true)
{
String message = input.readLine();
if (message == null)
break;
System.out.println(message);
}
Once a null message is received, you close your socket connection:
socket.close();
Then, go back to listening for more incoming YAC messages.