|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.cyberlab.local.recognition.extractor.net.SocketComm
public class SocketComm
This class implements the socket communication protocols (used by SocketLocalFeaturesExtractor
)
between the Android device and the socket feature extractor server.
The overall communication protocol follows this pattern:
1. Client sends authentication message.
2a. Server replies with an authentication message.
2b. Server closes connection if authentication fails.
3a. Client sends intent.
3b. Client closes connection if server authentication message fails.
3c. Client closes connection if server closes connection.
4. Server responds to intent.
5. If server understands intent the client announces a file send operation.
6. Server replies with OK if it understands intent.
7. If file send OK from server; client sends file and waits for reply.
8. Server performs operations based on the intent(3a) from the client
and announces that it wishes to send a file when it is finished.
9. Client responds with OK if it understands the intent.
10. Server sends file and closes its connection.
11. The client closes its connection.
See the specific methods for protocol details.
SocketLocalFeaturesExtractor#getFeatures(android.graphics.Bitmap)
,
authenticate(byte[], String, String)
,
extractIntent(byte[], String, String)
,
sendFile(File, byte[])
,
receiveFile(String, byte[])
Field Summary | |
---|---|
static java.lang.String |
AUTH_HEADER
|
(package private) java.io.BufferedInputStream |
bis
|
(package private) java.io.BufferedOutputStream |
bos
|
static int |
CHUNK_SIZE
|
static java.lang.String |
CLOSE_HEADER
|
static java.lang.String |
DELIMITER_HEADER
|
static java.lang.String |
END_HEADER
|
(package private) java.lang.String |
errorMsg
|
static java.lang.String |
EXTRACT_HEADER
|
static java.lang.String |
FILECOPY_HEADER
|
static java.lang.String |
OK_HEADER
|
(package private) java.net.Socket |
sock
|
static java.lang.String |
TAG
|
Constructor Summary | |
---|---|
SocketComm(java.lang.String ip,
int port,
int timeout)
|
Method Summary | |
---|---|
boolean |
authenticate(byte[] buffer,
java.lang.String authMessage,
java.lang.String authReply)
Description: Simple two way authenthication mechanism. |
void |
destroySocket()
Destroys the socket when it no longer is neeeded. |
boolean |
extractIntent(byte[] buffer,
java.lang.String featureType,
java.lang.String descriptorType)
Description: Client publish its intent. |
java.lang.String[] |
parseMessage(byte[] buffer,
int messageLength)
Helper class parsing the message and dividing it into a String array, removing the message delimiter |
java.lang.String |
receiveFile(java.lang.String path,
byte[] buffer)
|
java.lang.String[] |
receiveMessage(byte[] buffer)
Helper method for reading message from the socket |
boolean |
sendFile(java.io.File file,
byte[] buffer)
Description: Loads a file into a buffer and sends piece by piece via a socket object until complete. |
boolean |
sendMessage(java.lang.String message)
Helper method for sending a message to the socket |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String TAG
public static final int CHUNK_SIZE
public static final java.lang.String AUTH_HEADER
public static final java.lang.String FILECOPY_HEADER
public static final java.lang.String OK_HEADER
public static final java.lang.String END_HEADER
public static final java.lang.String DELIMITER_HEADER
public static final java.lang.String CLOSE_HEADER
public static final java.lang.String EXTRACT_HEADER
java.net.Socket sock
java.io.BufferedOutputStream bos
java.io.BufferedInputStream bis
java.lang.String errorMsg
Constructor Detail |
---|
public SocketComm(java.lang.String ip, int port, int timeout) throws SocketCommException
SocketCommException
Method Detail |
---|
public boolean authenticate(byte[] buffer, java.lang.String authMessage, java.lang.String authReply)
buffer
- The message bufferauthMessage
- The authentication messageauthReply
- The expected authentication message
public void destroySocket()
public boolean sendMessage(java.lang.String message)
message
- The message itself
public java.lang.String[] receiveMessage(byte[] buffer)
buffer
- Message buffer
public java.lang.String[] parseMessage(byte[] buffer, int messageLength)
buffer
- message buffermessageLength
- The length of the message
public boolean extractIntent(byte[] buffer, java.lang.String featureType, java.lang.String descriptorType)
buffer
- The message send bufferfeatureType
- The feature type we want to use detectiondescriptorType
- The descriptor type we want to use for extraction
public boolean sendFile(java.io.File file, byte[] buffer)
file
- The file that the client is sendingbuffer
- The send buffer
public java.lang.String receiveFile(java.lang.String path, byte[] buffer)
path
- buffer
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |