📄 smpp.java
字号:
}
private void smppInit(String s, int i)
throws UnknownHostException, IOException, socksException
{
log("SMPPINIT: creating socket host=" + s + ", port=" + i);
socket = socks.Socket(s, i);
log("SMPPINIT: creating output stream");
out = socket.getOutputStream();
lastSequenceNumber = 250;
log("SMPPINIT: creating fifo and table");
pendingRequests = new fifo();
pendingResponses = new table();
log("SMPPINIT: creating dispatcher");
dispatcher = new smppDispatcher(this);
log("SMPPINIT: returning");
receiverTarget = null;
}
void write(byte abyte0[], byte abyte1[])
throws SMSException, IOException
{
try
{
if(disconnected)
throw new SMSException(disconnectedError);
if(debugon)
log(" *** USE");
use();
if(debugon)
log(" *** USING");
out.write(abyte0);
if(abyte1 != null)
out.write(abyte1);
}
catch(IOException _ex)
{
bindtype = 0;
disconnected = true;
disconnectedError = 10010;
throw new IOException("SMSC Connection closed (remotely)");
}
catch(InterruptedException _ex)
{
throw new SMSException(10011);
}
finally
{
if(debugon)
log("*** FINISH");
finished();
if(debugon)
log("*** FINISHED");
}
}
public void bind(BindResponse bindresponse, Binding binding)
throws SMSException, IOException
{
if(binding == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
try
{
smppencoder.bind(binding);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
int i;
if(binding.target != null)
{
i = 1;
receiverTarget = binding.target;
} else
{
i = 2;
}
bindtype = i;
if(debugon)
log("binding");
putRequest(new smppRequest(i, binding, bindresponse), smppencoder);
}
public void bind(Binding binding)
throws SMSException, IOException
{
if(debugon)
log("Bind called");
bind(null, binding);
if(debugon)
log("bind: get sync response");
getSyncResponse();
}
public void get(Customer customer)
throws SMSException, IOException
{
get(null, customer);
getSyncResponse();
}
public void get(GetDLResponse getdlresponse, Address address)
throws SMSException, IOException
{
if(address == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
try
{
smppencoder.listDL(address);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(32, address, getdlresponse), smppencoder);
}
public String[] get(Address address)
throws SMSException, IOException
{
get(null, address);
return (String[])getSyncResponse();
}
public void get(GetMemberResponse getmemberresponse, Address address, String s)
throws SMSException, IOException
{
if(address == null || s == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
smDL smdl = new smDL();
smdl.source = address;
smdl.name = s;
try
{
smppencoder.viewDL(smdl);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(25, smdl, getmemberresponse), smppencoder);
}
public Member[] get(Address address, String s)
throws SMSException, IOException
{
get(null, address, s);
return (Member[])getSyncResponse();
}
Object getSyncResponse()
throws SMSException, IOException
{
smppSyncResponse smppsyncresponse;
try
{
Thread thread = Thread.currentThread();
smppsyncresponse = (smppSyncResponse)pendingResponses.delete(thread);
}
catch(InterruptedException _ex)
{
throw new SMSException(10011);
}
if(smppsyncresponse == null)
throw new SMSException(10008);
if(smppsyncresponse.exception != null)
{
if(smppsyncresponse.exception instanceof SMSException)
throw (SMSException)smppsyncresponse.exception;
if(smppsyncresponse.exception instanceof IOException)
throw (IOException)smppsyncresponse.exception;
else
throw new SMSException(10000, smppsyncresponse.exception.toString());
} else
{
return smppsyncresponse.returns;
}
}
public void details(DetailsResponse detailsresponse, Message message)
throws SMSException, IOException
{
if(message == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
try
{
smppencoder.queryDetails(message);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(36, message, detailsresponse), smppencoder);
}
public void details(Message message)
throws SMSException, IOException
{
details(null, message);
getSyncResponse();
}
protected void finalize()
{
if(debugon)
log("Finalizing");
close();
}
public void close()
{
Socket socket1;
try
{
use();
if(socket == null)
{
finished();
return;
}
socket1 = socket;
socket = null;
finished();
}
catch(Exception _ex)
{
socket1 = socket;
socket = null;
finished();
}
try
{
if(debugon)
log("sending unbind");
if(out != null && !disconnected)
putRequest(new smppRequest(6, null, null), null);
}
catch(Exception exception)
{
if(debugon)
log("sending unbind failed" + exception);
}
try
{
if(out != null)
{
out.close();
out = null;
}
}
catch(Exception _ex)
{
if(debugon)
log("Closing socket's output stream failed");
}
if(!Thread.currentThread().equals(dispatcher.dispatcherThread))
{
if(debugon)
log("WAITING FOR READER TO FINISH");
try
{
dispatcher.dispatcherThread.join();
}
catch(Exception exception1)
{
if(debugon)
log("Cant wait for dispatcher thread " + exception1);
}
}
if(debugon)
log("READER FINISHED");
try
{
if(socket1 != null)
{
socket1.close();
socket1 = null;
return;
}
}
catch(Exception _ex)
{
if(debugon)
log("Closing socket failed");
Object obj = null;
}
}
public void receive(Receiver receiver)
throws SMSException
{
if(bindtype != 1)
{
throw new SMSException(10012);
} else
{
receiverTarget = receiver;
return;
}
}
public void replace(ReplaceResponse replaceresponse, Message message)
throws SMSException, IOException
{
if(message == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
try
{
smppencoder.replace(message);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(7, message, replaceresponse), smppencoder);
}
public void replace(Message message)
throws SMSException, IOException
{
replace(null, message);
getSyncResponse();
}
public void status(StatusResponse statusresponse, Message message)
throws SMSException, IOException
{
if(message == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
try
{
smppencoder.query(message);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(3, message, statusresponse), smppencoder);
}
public void status(Message message)
throws SMSException, IOException
{
status(null, message);
getSyncResponse();
}
public void debug(boolean flag)
{
debugon = flag;
}
public void del(DelCustomerResponse delcustomerresponse, Customer customer)
throws SMSException, IOException
{
if(customer == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
try
{
smppencoder.deleteCustomer(customer);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(18, customer, delcustomerresponse), smppencoder);
}
public void del(Customer customer)
throws SMSException, IOException
{
del(null, customer);
getSyncResponse();
}
public void del(DelDLResponse deldlresponse, Address address, String s)
throws SMSException, IOException
{
if(address == null || s == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
smDL smdl = new smDL();
smdl.source = address;
smdl.name = s;
try
{
smppencoder.deleteDL(smdl);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(24, smdl, deldlresponse), smppencoder);
}
public void del(Address address, String s)
throws SMSException, IOException
{
del(null, address, s);
getSyncResponse();
}
public static void setSMSC(String s, int i)
{
smscHost = s;
smscPort = i;
}
public void del(DelMemberResponse delmemberresponse, Address address, String s, Member member)
throws SMSException, IOException
{
if(address == null || s == null || member == null)
throw new SMSException(10014);
smppEncoder smppencoder = new smppEncoder();
smDLModification smdlmodification = new smDLModification(address, s, member, true);
try
{
smppencoder.modDL(smdlmodification);
}
catch(encoderException encoderexception)
{
throw new SMSException(encoderexception);
}
putRequest(new smppRequest(23, smdlmodification, delmemberresponse), smppencoder);
}
public void del(Address address, String s, Member member)
throws SMSException, IOException
{
del(null, address, s, member);
getSyncResponse();
}
public void debug(boolean flag, boolean flag1)
{
if(dispatcher != null)
dispatcher.debugon = flag;
debugon = flag1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -