All Things CC:

All things Commuication & Computing….

Posts Tagged ‘Java

Year In Review: Programming

with 2 comments

Beginning of the year I embarked on a getting back in touch with my programming skills… and this year has been really successful. Here is what I accomplished, over the weekends and late nights:

·         I programmed extensively in first of half on the year on IOS, especially IOS5 and iPad. I still need to work on my design skills but I covered a lot of ground Table Views & Controllers, Storyboards, Network Programming, XML parsing, Notifications, Pull To Refresh etc.).

·         I refreshed my programming skills in Java by programming in OSGi Embedded environment…

·         And to complete my journey – I signed up for courses with edX and Coursera on Cloud Programming. I would have liked to do a project or two of mine but I had to be satisfied with the assignments and the tests that were done as a part of the course. I ended up learning about R, Ruby and Rails. I had signed up for a few courses but the three that I completed were:

o   CS169.1x Software As A Service @ edX

o   CS169.2x Software As A Service @ edX

o   Computing for Data Analysis @ Coursera [Data Analysis using R]

Written by Ashu Joshi

December 28, 2012 at 3:30 pm

Posted in Development

Tagged with , , , ,

SSDP Service using Java/OSGi [Part 3, ROM]

leave a comment »

In the last part I talked about how I implemented the SSDP code on the IOS app, to make my device discoverable – it has to be running the “SSDP Advertiser” – or a server that is listening to discovery messages.

The SSDP service runs as a thread when the OSGi bundle is installed and started – “AdvertiseServiceSSDP()”. [The call before that – SocksServer is the class that implements the network interface between the IOS app & the Plug Computer as explained in the project overview.

public void start(BundleContext bc) throws Exception {
    this.bc = bc;
    nServer = new SocksServer(bc);
    advtROMService = new AdvertiseServiceSSDP(bc);
  }

Here is the SSDP code:

public void run() {
String msg = "LISTEN-FOR=THIS MESSAGE";
String chkResponse = "RESPOND-WITH-THIS-MESSAGE";
try {
int port = 1900;
InetAddress listenSSDP = InetAddress.getByName("239.255.255.250");
MulticastSocket ms = new MulticastSocket(port);  // Create socket
ms.joinGroup(listenSSDP);
System.out.println("\n Rcvr started, Ready to Receive... \n");
boolean match = false;
do {
byte[] response = new byte[256];
DatagramPacket rspPkt = new DatagramPacket(response, response.length);
ms.receive(rspPkt);
//System.out.println("\n Done Receiving!\n");
String getResponse;
getResponse = new String(rspPkt.getData());
match = getResponse.regionMatches(0, msg, 0, msg.length());
if (match)
{
System.out.println("Controller found\n");
// Send Response
InetAddress IPAddress = rspPkt.getAddress();
byte[] sendData = new byte[1024];
String sendResponse = chkResponse;
sendResponse += IPAddress.getHostName();
sendResponse += "/:portAddr";
System.out.println(sendResponse);
sendData = sendResponse.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 1900);
ms.send(sendPacket);
System.out.println("Response Sent");
match = false;
}
} while(match==false);
} catch(Exception ignore) {
System.out.println(ignore.getMessage());
}
}

The above code when running on the Plug Computer(s) allows the IOS app to discover them. Of course the beauty is that this will work for all devices that support OSGi/JVM and have multicast networking support.

Written by Ashu Joshi

May 4, 2012 at 2:48 pm