60 likes | 266 Views
TCP/IP Protocol. Send stream of bytes. Each stream is a message which has msgid, msgLen, and the content. msgid and msgLen are unsigned short variables. msgLen tells the recipient the number of bytes to receive if string of variable length is involved. Definition of msgid:
E N D
TCP/IP Protocol • Send stream of bytes. • Each stream is a message which has msgid, msgLen, and the content. • msgid and msgLen are unsigned short variables. • msgLen tells the recipient the number of bytes to receive if string of variable length is involved.
Definition of msgid: #define CPAMID(c) ((((UInt16)c) << 8) + (UInt16)c) #define kInvoke CPAMID('i’) #define kInvokeRpy CPAMID('I') Example of msg structs: typedef struct InvokeMsg { MSG_HEADER;char clientID[CLIENT_ID_LEN] ;char methodName[METHOD_NAME_LEN]; char parameterList[1]; } InvokeMsg ; No pointers should be transferred. Every character should be contiguous. Initial idea: ChaimsAttrValList implemented as strings delimited by null character: string1\0string2\0. TCP/IP Interface
Sample Compiled Client Code ChaimsCallID Client::INVOKE (ChaimsClientID clientID, char* methodName, ChaimsAttrValList * attrvalseq) { /* create a struct to send */ struct InvokeMsg* msgToSend = new InvokeMsg; msgToSend->msgid = kInvoke; msgToSend->msgLen = INVOKE_MSG_PREFIX_LEN + attrvalseq->getLength(); strcpy(msgToSend->clientID, clientID); strcpy(msgToSend->methodName, methodName); memcpy(msgToSend->parameterList, attrvalseq->getValue(), TCPComm->send((char*)msgToSend, (int)msgToSend->msgLen); delete msgToSend; /* receive a struct */ struct InvokeRpy *rpy =TCPComm->receive(rpy, sizeof(rpy)); ChaimsCallID ret = rpy->callID; return ret; }
C++/Java Server/Client • Implementation language should be transparent. • Byte streams are received via TCP/IP. • Network order: • Integral values in Java are in network order, so functions like htonl should be used to convert data before send from C++.