📄 sessionmanager.java
字号:
/*
* Created on Aug 28, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.smpp.server;
import com.logica.smpp.Data;
import com.logica.smpp.Session;
import com.logica.smpp.TCPIPConnection;
import com.logica.smpp.debug.Debug;
import com.logica.smpp.debug.Event;
import com.logica.smpp.pdu.BindReceiver;
import com.logica.smpp.pdu.BindRequest;
import com.logica.smpp.pdu.BindResponse;
import com.logica.smpp.pdu.BindTransciever;
import com.logica.smpp.pdu.BindTransmitter;
import com.logica.smpp.pdu.UnbindResp;
public class SessionManager {
private GatewayProperties gp;
private Debug debug = null;
Session session;
private boolean bound = false;
private Event event = null;
protected SessionManager(GatewayProperties gp1)
{
gp = gp1;
debug = gp.getDebug();
event = gp.getEvent();
}
public Session bind()
{
debug.enter(this, "SMPPSender.bind()");
try
{
if (bound)
{
System.out.println("Already bound, unbind first.");
return session;
}
BindRequest request = null;
BindResponse response = null;
String bindOption = gp.getBindOption();
// input values
if (bindOption.compareToIgnoreCase("t") == 0)
{
request = new BindTransmitter();
} else if (bindOption.compareToIgnoreCase("r") == 0)
{
request = new BindReceiver();
} else if (bindOption.compareToIgnoreCase("tr") == 0)
{
request = new BindTransciever();
} else
{
System.out
.println("Invalid bind mode, expected t, r or tr, got " + bindOption + " Operation canceled.");
return session;
}
TCPIPConnection connection = new TCPIPConnection(gp.getIpAddress(), gp.getPort());
connection.setReceiveTimeout(20 * 1000);
session = new Session(connection);
// set values
request.setSystemId(gp.getSystemId());
request.setPassword(gp.getPassword());
request.setSystemType(gp.getSystemType());
request.setInterfaceVersion((byte) 0x34);
request.setAddressRange(gp.getAddressRange());
// send the request
//System.out.println("Bind request " + request.debugString());
response = session.bind(request);
//System.out.println("Bind response " + response.debugString());
if (response.getCommandStatus() == Data.ESME_ROK)
{
bound = true;
}
System.out.println(gp.getSystemId() + " -- Bind to the SMPP server on address -> "+ gp.getIpAddress()+":"+gp.getPort());
return session;
} catch (Exception e)
{
event.write(e, "");
debug.write("Bind operation failed. " + e);
System.out.println("Bind operation failed. " + e);
e.printStackTrace();
} finally
{
//debug.exit(this);
}
return session;
}
private void unbind()
{
debug.enter(this, "SMPPTest.unbind()");
try
{
if (!bound)
{
System.out.println("Not bound, cannot unbind.");
return;
}
// send the request
System.out.println("Going to unbind.");
if (session.getReceiver().isReceiver())
{
System.out.println("It could take a while to stop the receiver.");
}
UnbindResp response = session.unbind();
System.out.println("Unbind response " + response.debugString());
bound = false;
} catch (Exception e)
{
event.write(e, "");
debug.write("Unbind operation failed. " + e);
System.out.println("Unbind operation failed. " + e);
} finally
{
debug.exit(this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -