Home > other >  Realize the CMPP protocol socket connection timeout, seeks to solve.
Realize the CMPP protocol socket connection timeout, seeks to solve.

Time:10-20

Package HTTP;

Import the Java. IO. IOException;
Import the Java. IO. InputStream;
Import the Java. IO. OutputStream;
Import the Java. IO. UnsupportedEncodingException;
The import java.net.Socket;
The import java.net.UnknownHostException;
Import the Java. Nio. ByteBuffer;
Import the Java. Nio. ByteOrder;
Import the Java. Security. NoSuchAlgorithmException;
Import the Java. Text. SimpleDateFormat;
Import the Java. Util. Date;

Public class SocketHttpServer3 {
Public static int Total_Length;//bytes
Public static int Command_Id;//command or response type
Public static int Sequence_Id; No.//message
Public static byte [] Source_Addr=new byte [6].//source address
Public static byte [] AuthenticatorSource=new byte [16].//identify the source address
Public static int Timestamp;//time
Private String strtimeStamp;//time
Private String spId="123456";//login ID

Public SocketHttpServer3 (int I) throws UnsupportedEncodingException,
NoSuchAlgorithmException {
Total_Length=4;
Command_Id=4;
Sequence_Id=I;
Source_Addr=spId. GetBytes ();
SimpleDateFormat sf=new SimpleDateFormat (" MMDDHHMMSS ");
StrtimeStamp=sf. The format (new Date ());
Timestamp=Integer. The valueOf (strtimeStamp). IntValue ();
}

Public static void main (String [] args) throws UnknownHostException,
IOException, NoSuchAlgorithmException {
The Socket Socket=null;
The socket=new socket (" 2 xx. 6 x. 10 x. 19 x ", 9999);
New SocketHttpServer3 (1);
OutputStream OS=socket. GetOutputStream ();
OS. Write (SocketHttpServer3 toBytes ());
OS. The flush ();
InputStream is=socket.getInputStream();
If ((is) the read ())==0) {
System. The out. Println (" login success ");
}
OS. The flush ();
int a=0;
Is the skip (25);
While ((a=is the read ())!=1) {
System. The out. Println (" RESULT "+ a);
}
}

Public static byte [] toBytes () {
Byte [] b=new byte [39];
ByteBuffer bb=ByteBuffer. Wrap (b, 0, 39);
Bb. Order (ByteOrder. BIG_ENDIAN);
Bb. PutInt (Total_Length);
Bb. PutInt (Command_Id);
Bb. PutInt (Sequence_Id);
Bb. Put (Source_Addr);
Bb. PutInt (Timestamp);
Bb. Put (AuthenticatorSource);

Return b;
}

}

CodePudding user response:

Connection timeout and CMPP protocol is not too big relations, the first thing you want to make sure the operator to your gateway address not right, you can first test can pass, the gateway can pass to debug, cmpp2.0 connection is not on the gateway connection timeout, landing information is not correct to logon failure or timeout if, forget it
  • Related