|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.montsuqi.client.Connection
class Connection
A class that represents client/server connection.
This class implements methods for sending/receiving basic data types such as booleans, integers and strings.
| Field Summary | |
|---|---|
protected java.io.DataInput |
in
|
protected java.io.DataOutput |
out
|
| Constructor Summary | |
|---|---|
Connection(java.net.Socket s,
java.lang.String encoding,
boolean networkByteOrder)
Constructs a Connection instance. |
|
| Method Summary | |
|---|---|
(package private) void |
close()
|
int |
getLastDataType()
Returns the last(latest) data type received. |
byte[] |
receiveBinaryData()
|
(package private) boolean |
receiveBoolean()
|
boolean |
receiveBooleanData()
|
(package private) int |
receiveChar()
|
(package private) int |
receiveDataType()
Receives a data type. |
int |
receiveDataTypeWithCheck(int expected)
Receives a data type. |
(package private) java.math.BigDecimal |
receiveFixed()
|
java.math.BigDecimal |
receiveFixedData()
|
(package private) double |
receiveFloat()
|
int |
receiveInt()
|
int |
receiveIntData()
|
(package private) int |
receiveLength()
Receives length of 4-byte long. |
(package private) int |
receiveLong()
Receives an integer of 4-byte long. |
(package private) byte |
receivePacketClass()
Receives a packet class. |
java.lang.String |
receiveString()
Receives a string |
(package private) java.lang.String |
receiveStringBody(int size)
Receives string data part of given size. |
java.lang.String |
receiveStringData()
|
(package private) void |
sendBoolean(boolean data)
|
void |
sendBooleanData(int type,
boolean value)
|
(package private) void |
sendChar(byte data)
|
void |
sendDataType(int c)
Sends a data type. |
(package private) void |
sendFixed(java.math.BigDecimal xval)
|
void |
sendFixedData(int type,
java.math.BigDecimal xval)
|
(package private) void |
sendFloat(double data)
|
void |
sendInt(int data)
|
void |
sendIntegerData(int type,
int value)
|
(package private) void |
sendLength(int size)
Sends length of 4-byte long. |
(package private) void |
sendLong(int data)
|
void |
sendPacketClass(int c)
Sends a packet class. |
void |
sendString(java.lang.String s)
Sends a string. |
void |
sendStringData(int type,
java.lang.String str)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.io.DataInput in
protected java.io.DataOutput out
| Constructor Detail |
|---|
Connection(java.net.Socket s,
java.lang.String encoding,
boolean networkByteOrder)
throws java.io.IOException
Constructs a Connection instance.
Input/Output streams are initialized correctly by networkByteOrder.
s - the socket to communicate.encoding - the encoding to use.networkByteOrder - true if networkByteOrder(Big Endian) is used. false otherwise(Litle Endian).
java.io.IOException| Method Detail |
|---|
public void sendPacketClass(int c)
throws java.io.IOException
Sends a packet class.
c - packet class. should use constants defined in PacketClass.
java.io.IOException - on I/O error.
byte receivePacketClass()
throws java.io.IOException
Receives a packet class.
java.io.IOException - on I/O error.
public void sendDataType(int c)
throws java.io.IOException
Sends a data type.
c - data type. should use constants defined in Type.
java.io.IOException - on I/O error.
int receiveDataType()
throws java.io.IOException
Receives a data type.
java.io.IOException - on I/O error.
public int receiveDataTypeWithCheck(int expected)
throws java.io.IOException
Receives a data type. If the type does not match to expected type, an IOException is thrown.
expected - data type that should have been sent from the server.
java.io.IOException - on I/O error or type mismatch.public int getLastDataType()
Returns the last(latest) data type received.
void sendLength(int size)
throws java.io.IOException
Sends length of 4-byte long.
size - the length to send.
java.io.IOException - on I/O error.
int receiveLength()
throws java.io.IOException
Receives length of 4-byte long.
java.io.IOException - on I/O error.
public void sendString(java.lang.String s)
throws java.io.IOException
Sends a string.
If the client environment uses MS932 characters, incompatible characters are converted to compatible ones.
s - the string to send.
java.io.IOException - on I/O error.
java.lang.String receiveStringBody(int size)
throws java.io.IOException
Receives string data part of given size.
size - the size of the data to be received.
java.io.IOException - on I/O error.
public java.lang.String receiveString()
throws java.io.IOException
Receives a string
At first, the length of the string is received. Then the string's data of that length are received and built into a String.
java.io.IOException - on I/O error.
int receiveLong()
throws java.io.IOException
Receives an integer of 4-byte long.
java.io.IOException - on I/O error.
void sendLong(int data)
throws java.io.IOException
java.io.IOException
public int receiveInt()
throws java.io.IOException
java.io.IOException
public void sendInt(int data)
throws java.io.IOException
java.io.IOException
int receiveChar()
throws java.io.IOException
java.io.IOException
void sendChar(byte data)
throws java.io.IOException
java.io.IOException
double receiveFloat()
throws java.io.IOException
java.io.IOException
void sendFloat(double data)
throws java.io.IOException
java.io.IOException
boolean receiveBoolean()
throws java.io.IOException
java.io.IOException
void sendBoolean(boolean data)
throws java.io.IOException
java.io.IOException
void sendFixed(java.math.BigDecimal xval)
throws java.io.IOException
java.io.IOException
java.math.BigDecimal receiveFixed()
throws java.io.IOException
java.io.IOException
public java.math.BigDecimal receiveFixedData()
throws java.io.IOException
java.io.IOException
public void sendFixedData(int type,
java.math.BigDecimal xval)
throws java.io.IOException
java.io.IOException
public void sendStringData(int type,
java.lang.String str)
throws java.io.IOException
java.io.IOException
public java.lang.String receiveStringData()
throws java.io.IOException
java.io.IOException
public void sendIntegerData(int type,
int value)
throws java.io.IOException
java.io.IOException
public int receiveIntData()
throws java.io.IOException
java.io.IOException
public void sendBooleanData(int type,
boolean value)
throws java.io.IOException
java.io.IOException
public boolean receiveBooleanData()
throws java.io.IOException
java.io.IOException
public byte[] receiveBinaryData()
throws java.io.IOException
java.io.IOException
void close()
throws java.io.IOException
java.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||