Java Code to send Jabber Instance Message
ConnectionConfiguration config = new ConnectionConfiguration("localhost",5222);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login("demo", "password");
for(int i=0 ; i < 10; i ++)
{
Message message = new Message();
message.setTo("admin@localhost");
message.setBody("Test message from demo " + i);
message.setType(Message.Type.chat);
connection.sendPacket(message);
}
JABBER Installation
Download location
http://www.ejabberd.im/ejabberd-2.0.1
Or
http://www.process-one.net/en/ejabberd/downloads
Step1:
Download Linux x86 32-bits Installer from the download page
Step2:
ejabberd-2.0.1_2-linux-x86-installer.bin.gz
untar the gunzip using following command
tar –d ejabberd-2.0.1_2-linux-x86-installer.bin.gz
You will get
ejabberd-2.0.1_2-linux-x86-installer.bin
execute the bin file using following command (chmod 777 ejabberd-2.0.1_2-linux-x86-installer.bin)
./ejabberd-2.0.1_2-linux-x86-installer.bin
You will get following screens
Improving the speed
%% For all users except admins used "normal" shaper
{access, c2s_shaper, [{none, admin},
{normal, all}]}.
Change "normal" to "fast":
%% For all users except admins used "fast" shaper
{access, c2s_shaper, [{none, admin},
{fast, all}]}.
Wednesday, August 6, 2008
J2ME RMS
package rms;
import javax.microedition.midlet.*;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.lcdui.*;
import javax.swing.JLabel;
import java.awt.Font;
import java.io.*;
public class ReadWriteRecord
extends MIDlet implements CommandListener {
private Display display;
private Alert alert;
private Form form;
private Command exit;
private Command read,readByte;
private Command write,writeByte;
private Command delete;
private RecordStore recordstoreRead,recordstoreWrite,recordstoreDelete = null;
RecordEnumeration recEnum;
public ReadWriteRecord() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
read = new Command("Read", Command.SCREEN, 1);
readByte = new Command("Read Byte", Command.SCREEN, 1);
write = new Command("Write", Command.SCREEN, 1);
writeByte = new Command("Write Byte", Command.SCREEN, 1);
delete = new Command("Delete",Command.SCREEN,2);
//////////////////////////
//Font font = new Font("TAU_Elango_Ragham",22,22);
///////////////////////////
form = new Form("Mixed Record " + "\"வாழ்க வளமுடன்\"");
form.addCommand(exit);
form.addCommand(read);
form.addCommand(write);
form.addCommand(readByte);
form.addCommand(writeByte);
form.addCommand(delete);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp( boolean unconditional )
{
}
public void commandAction(Command command, Displayable displayable)
{
if (command == exit)
{
destroyApp(true);
notifyDestroyed();
}
else if (command == read)
{
doRead();
}
else if (command == write)
{
doWrite();
}
else if (command == readByte)
{
doReadByte();
}
else if (command == writeByte)
{
doWriteByte();
}
else if (command == delete)
{
doDelete();
}
}
public void doRead()
{
try
{
recordstoreRead = RecordStore.openRecordStore("myRecordStoreUTF", true );
System.out.println("NumRecords : " + recordstoreRead.getNumRecords());
for (int i = 1; i <= recordstoreRead.getNumRecords(); i++)
{
byte[] byteInputData = new byte[50];
recordstoreRead.getRecord(i, byteInputData, 0);
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
DataInputStream inputDataStream = new DataInputStream(inputStream);
StringItem idItem = new StringItem("Id: ", String.valueOf(inputDataStream.readInt()));
StringItem nameItem = new StringItem("Name :", inputDataStream.readUTF());
StringItem ageItem = new StringItem("Age :", inputDataStream.readUTF());
StringItem sexItem = new StringItem("Sex :", inputDataStream.readUTF());
form.append(idItem);
form.append(nameItem);
form.append(ageItem);
form.append(sexItem);
}
Alert a = new Alert("Success", "Read Records finished", null, AlertType.INFO);
Display.getDisplay(this).setCurrent(a);
}
catch(Exception ex)
{
Alert a = new Alert("Fail to read", ex.getMessage(), null, AlertType.ERROR);
Display.getDisplay(this).setCurrent(a);
System.out.println("Unable to read the Record");
ex.printStackTrace();
}
}
public void doWrite()
{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream( bout );
try
{
recordstoreWrite = RecordStore.openRecordStore("myRecordStoreUTF", true );
int input_id = 1;
String input_name = "Senthil";
String input_age = "29";
String input_sex = "Male";
byte dataArray[];
try
{
dout.writeInt( input_id );
dout.writeUTF( input_name );
dout.writeUTF( input_age );
dout.writeUTF( input_sex);
dout.close();
dataArray = bout.toByteArray();
recordstoreWrite.addRecord( dataArray, 0, dataArray.length );
}
catch( RecordStoreException e )
{
// handle RMS error here
}
catch( IOException e )
{
// handle IO error here
}
recordstoreWrite.closeRecordStore();
Alert a = new Alert("Success to Write", "Record written into File", null, AlertType.INFO);
Display.getDisplay(this).setCurrent(a);
}
catch(Exception ex)
{
Alert a = new Alert("Fail to write", ex.getMessage(), null, AlertType.ERROR);
Display.getDisplay(this).setCurrent(a);
System.out.println("Unable to write the Record");
ex.printStackTrace();
}
}
}
import javax.microedition.midlet.*;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.lcdui.*;
import javax.swing.JLabel;
import java.awt.Font;
import java.io.*;
public class ReadWriteRecord
extends MIDlet implements CommandListener {
private Display display;
private Alert alert;
private Form form;
private Command exit;
private Command read,readByte;
private Command write,writeByte;
private Command delete;
private RecordStore recordstoreRead,recordstoreWrite,recordstoreDelete = null;
RecordEnumeration recEnum;
public ReadWriteRecord() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
read = new Command("Read", Command.SCREEN, 1);
readByte = new Command("Read Byte", Command.SCREEN, 1);
write = new Command("Write", Command.SCREEN, 1);
writeByte = new Command("Write Byte", Command.SCREEN, 1);
delete = new Command("Delete",Command.SCREEN,2);
//////////////////////////
//Font font = new Font("TAU_Elango_Ragham",22,22);
///////////////////////////
form = new Form("Mixed Record " + "\"வாழ்க வளமுடன்\"");
form.addCommand(exit);
form.addCommand(read);
form.addCommand(write);
form.addCommand(readByte);
form.addCommand(writeByte);
form.addCommand(delete);
form.setCommandListener(this);
}
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp( boolean unconditional )
{
}
public void commandAction(Command command, Displayable displayable)
{
if (command == exit)
{
destroyApp(true);
notifyDestroyed();
}
else if (command == read)
{
doRead();
}
else if (command == write)
{
doWrite();
}
else if (command == readByte)
{
doReadByte();
}
else if (command == writeByte)
{
doWriteByte();
}
else if (command == delete)
{
doDelete();
}
}
public void doRead()
{
try
{
recordstoreRead = RecordStore.openRecordStore("myRecordStoreUTF", true );
System.out.println("NumRecords : " + recordstoreRead.getNumRecords());
for (int i = 1; i <= recordstoreRead.getNumRecords(); i++)
{
byte[] byteInputData = new byte[50];
recordstoreRead.getRecord(i, byteInputData, 0);
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
DataInputStream inputDataStream = new DataInputStream(inputStream);
StringItem idItem = new StringItem("Id: ", String.valueOf(inputDataStream.readInt()));
StringItem nameItem = new StringItem("Name :", inputDataStream.readUTF());
StringItem ageItem = new StringItem("Age :", inputDataStream.readUTF());
StringItem sexItem = new StringItem("Sex :", inputDataStream.readUTF());
form.append(idItem);
form.append(nameItem);
form.append(ageItem);
form.append(sexItem);
}
Alert a = new Alert("Success", "Read Records finished", null, AlertType.INFO);
Display.getDisplay(this).setCurrent(a);
}
catch(Exception ex)
{
Alert a = new Alert("Fail to read", ex.getMessage(), null, AlertType.ERROR);
Display.getDisplay(this).setCurrent(a);
System.out.println("Unable to read the Record");
ex.printStackTrace();
}
}
public void doWrite()
{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream( bout );
try
{
recordstoreWrite = RecordStore.openRecordStore("myRecordStoreUTF", true );
int input_id = 1;
String input_name = "Senthil";
String input_age = "29";
String input_sex = "Male";
byte dataArray[];
try
{
dout.writeInt( input_id );
dout.writeUTF( input_name );
dout.writeUTF( input_age );
dout.writeUTF( input_sex);
dout.close();
dataArray = bout.toByteArray();
recordstoreWrite.addRecord( dataArray, 0, dataArray.length );
}
catch( RecordStoreException e )
{
// handle RMS error here
}
catch( IOException e )
{
// handle IO error here
}
recordstoreWrite.closeRecordStore();
Alert a = new Alert("Success to Write", "Record written into File", null, AlertType.INFO);
Display.getDisplay(this).setCurrent(a);
}
catch(Exception ex)
{
Alert a = new Alert("Fail to write", ex.getMessage(), null, AlertType.ERROR);
Display.getDisplay(this).setCurrent(a);
System.out.println("Unable to write the Record");
ex.printStackTrace();
}
}
}
Subscribe to:
Posts (Atom)