package hu.ozekisms;
import java.io.*;
import java.util.Scanner;
public class TestTcpSms {
/**
* @param args
*/
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
String host = "localhost";
int port = 33049;
String username = "admin";
String password = "abc123";
/**
* Connect to Ozeki NG SMS Gateway and logging in.
*/
MyOzSmsClient osc = new MyOzSmsClient(host, port);
osc.login(username, password);
System.out.println("SMS message:");
/**
* If logged in send "Text message" to number "+00112233"
*/
if(osc.isLoggedIn()) {
osc.sendMessage("phone number", "Test Message");
}
sc.nextLine();
osc.logout();
/**
* Receiving message:
*
* If you want to receive messages you can use doOnMessageReceived in MyOzSmsClient.java
* That's an event, which runs automatically when a message is received.
*/
} catch (IOException e) {
System.out.println(e.toString());
e.printStackTrace();
} catch (InterruptedException e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
package hu.ozekisms;
import java.io.*;
import java.util.*;
import hu.ozeki.*;
public class MyOzSmsClient extends OzSmsClient{
public MyOzSmsClient(String host, int port) throws IOException, InterruptedException {
super(host, port);
// TODO Auto-generated constructor stub
}
@Override
public void doOnMessageAcceptedForDelivery(OzSMSMessage sms) {
Date now = new Date();
System.out.println(now.toString() + " Message accepted for delivery. ID: " + sms.messageId);
}
@Override
public void doOnMessageDeliveredToHandset(OzSMSMessage sms) {
Date now = new Date();
System.out.println(now.toString() + " Message delivered to handset. ID: " + sms.messageId);
}
@Override
public void doOnMessageDeliveredToNetwork(OzSMSMessage sms) {
Date now = new Date();
System.out.println(now.toString() + " Message delivered to network. ID: " + sms.messageId);
}
@Override
public void doOnMessageDeliveryError(OzSMSMessage sms) {
Date now = new Date();
System.out.println(now.toString() + " Message could not be delivered. ID: " + sms.messageId + " Error message: " + sms.errorMessage + "\r\n");
}
@Override
public void doOnMessageReceived(OzSMSMessage sms) {
Date now = new Date();
System.out.println(now.toString() + " Message received. Sender address: " + sms.sender + " Message text: " + sms.messageData + " at: "+ sms.receivedDate);
}
@Override
public void doOnClientConnectionError(int errorCode, String errorMessage) {
Date now = new Date();
System.out.println(now.toString() + " Message code: " + errorCode + ", Message: " + errorMessage);
}
}
java.io.IOException: An established connection was aborted by the software in
your hostmachine
java.io.IOException: An established connection was aborted by the software in
yourhost machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233)
at sun.nio.ch.IOUtil.read(IOUtil.java:206)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)
at hu.ozeki.OzSmsClient.run(OzSmsClient.java:87)
任何人都可以修复此错误吗? 我通过Ozeki NG SMS Gateway发送短信。
答案 0 :(得分:1)
我认为您没有为短信网关付费,这就是为什么它无效http://www.ozekisms.com/index.php?owpn=27
我是对的吗?
另一个原因是您可能提供了错误的发送参数:
osc.sendMessage("phone number", "Test Message");
“电话号码”应替换为一些真实的电话号码