public void | send(java.lang.String type, int segNum, java.lang.String address)Send a CBS message.
String urlFragment = address.substring(CBS_SCHEME.length());
try {
conn = cbsmess.openPrim(urlFragment);
} catch (IOException ioe) {
System.err.println("Exception thrown by CBS Test server: " + ioe);
}
int num = 0;
if (type.equals("gsm7")) {
TextMessage tmsg = (TextMessage)cbsmess.newMessage(MessageConnection.TEXT_MESSAGE, address);
// construct the message
switch (segNum){
case 1:
num = 24;
break;
case 2:
num = 26;
break;
case 3:
num = 50;
break;
case 4:
num = 74;
break;
default:
num = 0;
}
String long_msg = "";;
for (int i = 0; i < num; i++) {
long_msg += "Hello "; // the string contains 6 chars
}
tmsg.setPayloadText(long_msg);
try {
conn.send(tmsg);
} catch (Exception e) {
System.err.println("Exception thrown by CBS Test server: " + e);
}
} else if (type.equals("ucs2")) {
TextMessage tmsg = (TextMessage)cbsmess.newMessage(MessageConnection.TEXT_MESSAGE, address);
// construct the message
switch (segNum){
case 1:
num = 60;
break;
case 2:
num = 68;
break;
case 3:
num = 128;
break;
case 4:
num = 190;
break;
default:
num = 0;
}
char[] ucs_chars = new char[num];
for (int i = 0; i < num; i++) {
ucs_chars[i] = UCS_CHAR; // char UCS_CHAR = 0x00a4;
}
String long_msg = new String(ucs_chars);
tmsg.setPayloadText(long_msg);
try {
conn.send(tmsg);
} catch (Exception e) {
System.err.println("Exception thrown by CBS Test server: " + e);
}
} else if (type.equals("binary")) {
BinaryMessage bmsg = (BinaryMessage)cbsmess.newMessage(MessageConnection.BINARY_MESSAGE, address);
// construct the message
switch (segNum){
case 1:
num = 130;
break;
case 2:
num = 136;
break;
case 3:
num = 260;
break;
case 4:
num = 390;
break;
default:
num = 0;
}
byte[] byte_msg = new byte[num];
for (int i = 0; i < num; i++) {
byte_msg[i] = (byte) i; // create a byte[]
}
bmsg.setPayloadData(byte_msg);
try {
conn.send(bmsg);
} catch (Exception e) {
System.err.println("Exception thrown by CBS Test server: " + e);
}
}
|