Translation of Sun's Help File - (Javax.wireless.Messaging.MessageConnection)

zhaozj2021-02-16  51

The latest version of J2ME adds support for SMS, will be a document under javax.wireless.messaging in the future.

Translate according to my understanding, because the level is limited, the error is inevitable, I hope everyone is correct.

My e-mail: flyhelleryuanwei@yahoo.com.cn

Javax.wireless.Messaging Interface MessageConnection

Interface MessageConnection defines some basic mechanisms for sending and receiving SMS. Such as: Accept and send text messages, establish a new SMS factory method (Factory method), and calculate the number of segments to be divided when the underlying protocol is sent. A MessageConnection can be obtained by connector.open () and the program should be closed with Close (). If any declaration of the MessageConnection throws the IOException, IOEXCEPTION is thrown after it is turned off.

The message can be sent by a connection. A connection can not be defined as a server (Server) mode or client mode.

In client mode, the connection can only be sent. The connection of the client mode can be obtained when calling connector.open (). This method will return a MessageConnection object.

In Server mode, a connection can be sent or acceptable. The connection of the server mode can be transmitted in the CONNECTOR.Open () to pass the identity of this connection (related to the protocol, such as: port number). If the specified identifier has been occupied by other system programs or Java programs, Connector.Open () will throw IOEXCEPTION. The Java program can open the MessageConnection with any unbeatted End Point identifier, but some security protocols may not allow it to send or accept information on that end point.

This interface does not assume details related to any protocol, so it is suitable for all wireless message protocols.

A program can open nothing MessageConnection at the same time, and these connections can be server mode, or client mode. The program can create an instance that implements the MessageListener interface, and registers it to MessageConnection to make MessageConnection, which is notified in information. This doesn't have to hang a thread in order to wait for the received information.

------------------------------------ Field Detail

Text_message public static final java.lang.string text_message represents constant of text information ("TEXT"). If this constant is used as a parameter for newMessage (), an instance that implements the TextMessage interface will be returned.

Binary_message public static final java.lang.string binary_message

Represents constant of binary information (value "binary"). If this constant is used as a parameter for newMessage (), an instance that implements a BinaryMessage interface will be returned.

---------------------------- Method Detail

NewMessage Public Message NewMessage (Java.lang.String Type)

Create an instance of a Message according to the specified parameters. When Text_Message is incomed to return an instance that implements the TextMessage interface. When binary_message is incoming, an instance that implements a binaryMessage interface. Implementors can also define other constants and sub-interfaces for the corresponding Message. The type of TYPE that is incorporated into the parameter is case sensitive, which will be compared by string.equals (), so only the value of the incoming parameter is equal to the value of the defined constant. When this method is called by the MessageConnection in the client mode, the newly established Message object will contain the destination address of this connection.

When this method is called by the MessageConnection in server mode, the newly established Message object will not contain the destination address. You must set the destination address before sending the message.

If the connection is closed, this method returns a Message instance.

Parameters: TYPE: What kind of message is established. The basic message type is defined in this interface. Returns: Message instances established depending on the parameters incorporated. Throws: java.lang.illegalargumentException: When the parameter does not text_Message, binary_message, or other implementation will be thrown when the constant defined by its special protocol. -------------------------------------

NewMessagePublic Message NewMessage (Java.lang.String Type, Java.lang.String Address) Creates a Message instance for address as address -ical address by specifying parameters. The meaning of Type is the same.

If the connection is closed, this method returns a Message instance.

Parameters: TYPE: What kind of message is established. The basic message type is defined in this interface. Address: Destination address. Returns: Message instances established depending on the parameters incorporated. Throws: java.lang.illegalargumentException: When the parameter does not text_Message, binary_message, or other implementation will be thrown when the constant defined by its special protocol.

------------------------------------- Sendpublic void send (Message MSG) throws java.ioException Java.io.InterruptedioException

send Message. Paramenters: msg: The information sent. Throws: java.io.ioException: When the information cannot be sent, the network fault, or the connection is thrown. Java.lang.illegalargumentException: When the information is incomplete, illegal information, or when the length of information exceeds the maximum length required by the protocol, it is thrown. An example of a special information contains illegal information is that the MessageConnceTion tries to send it does not support the type of information. Therefore, the information should always be sent with the MessageConncetion created it. Java.io.InterruptedioException: If the timeout occurs when trying to send information, or when the method is called, the connection is closed. Java.lang.NullPointersRexception: If the MSG is NULL. Java.lang.securityException: If the program does not send the permissions of the information.

------------------------------------- ReceivePublic Message Receive () THROWS JAVA.IOEXCEPTION JAVA. IO.InterruptedioException receives information.

If there is no information, this method hangs until information arrives, or the messageconnection is turned off.

Returns: a Message object that represents information accepted. THROWS: Java.io.IOException: This is thrown when the following event occurs: 1. An error occurred in accepting information. 2. This method is called when the connection is closed is called. 3. This method is called in the client mode. Java.io.InterruptedioException: Throw when it is turned off when this method is executed. Java.lang.securityException: If the program does not receive the permission to receive information in the specified port.

-------------------------------------

SetMessagelistenerpublic void setMessagelistener (MessageListener L) throws java.io.ioException

Registering MessageListener to this MessageConnection makes notifications when the message arrives.

If the message queue is not empty when calling this method, the newly registered listner will be immediately notified (each message is notified once). Only one of the only Listener registration to MessageConnection at any time, the newly set Listener will automatically replace the old Listener. The parameters of null for this method will cancel the Listener before.

Parameters: 1: The registered messagener. If the value is null, the current Listener will be logged out so that no notifications are received. Throws: java.lang.securityException: If the program does not receive the permission to receive information in the specified port. Java.lang.ioException: If this connection is turned off, or trying to use this method in client mode.

-------------------------------------

NumberofsegmentsPublic int Numberofsegments (Message MSG)

Returns the number of segments to the underlying protocol to send information. This method does not send information, just calculate the needs of the protocol.

This method will calculate the number of segments generated by the appropriate protocol, which does not care about the upper limit of the number specified in the specific protocol implementation. Those limits are the protocol related, and will be pointed out in the realized text.

When the connection is closed, this method will return to the number of segments calculated.

Paramenters: msg: Information used to calculate. Returns: The protocol section you need to send information. If it is last 0, this information cannot be sent with the current underlying protocol.

转载请注明原文地址:https://www.9cbs.com/read-23709.html

New Post(0)