Skip to main content

Featured

Adobe Experience Manager - Create an OSGI Configuration

 In this article, let's create an OSGi configuration, configure it and use it in AEM code. So now let's get started with the creation of an OSGi configuration. Technical details and Assumptions: All the following details are tested in AEM version 6.5.8, Java version 11.0.2 Creation of OSGi configuration: To create an OSGi configuration we need to create an ObjectClassDefinition. I have included a sample OCD configuration, which can be used as a reference to create one. The next step would be to create an interface and an implementation that can help fetch the OSGi configurations.  Interface: Implementation: Let's try to use the OSGi configuration created so far in Models/Servlets. For demonstration purposes, I used AEM Models here, but the same can be implemented in Servlets too. Now that we have created the OSGi configuration. Once building the code, we should be able to see the OSGi configuration in the web console (http://localhost:4502/system/console/configMgr) C...

Implementation of User Datagram Protocol (UDP) with Domain Name System (DNS)

This is a java program to implement DNS through UDP, provides a DNS server and a client, were the client requests for the IP Address of the specific Domain name to the DNS server

UDPserver.java:

import java.io.*;

import java.net.*;

class UDPserver

{

public static DatagramSocket ds;

public static byte buffer[]=new byte[1024];

public static int clientport=7898,serverport=7908;

public static void main(String args[])throws Exception

{

ds=new DatagramSocket(clientport);

System.out.println("press ctrl+c to quit the program");

BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));

InetAddress ia=InetAddress.getLocalHost();

while(true)

{

DatagramPacket p=new DatagramPacket(buffer,buffer.length);

ds.receive(p);

String psx=new String(p.getData(),0,p.getLength());

System.out.println("Client:"+ psx);

InetAddress ib=InetAddress.getByName(psx);

System.out.println("Server output:"+ib);

String str=dis.readLine();

if(str.equals("end"))
break;

buffer=str.getBytes();

ds.send(new DatagramPacket(buffer,str.length(),ia,serverport));

}

}

}

UDPclient.java:

import java .io.*;

import java.net.*;

class UDPclient

{

public static DatagramSocket ds;

public static int clientport=7898,serverport=7908;

public static void main(String args[])throws Exception

{

byte buffer[]=new byte[1024];

ds=new DatagramSocket(serverport);

BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));

System.out.println("server waiting");

InetAddress ia=InetAddress.getLocalHost();

while(true)

{

System.out.println("Client:");

String str=dis.readLine();

if(str.equals("end"))

break;

buffer=str.getBytes();

ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));

DatagramPacket p=new DatagramPacket(buffer,buffer.length);

ds.receive(p);

String psx=new String(p.getData(),0,p.getLength());

System.out.println("Server:"+ psx);

}

}

}

Output:

Comments

Popular Posts