+++ /dev/null
-/*\r
- * Copyright (c) 2003 University of Murcia. All rights reserved.\r
- * --------------------------------------------------------------\r
- * For more information, please see <http://www.umu.euro6ix.org/>.\r
- */\r
-\r
-package org.umu.cops.stack;\r
-\r
-import java.io.IOException;\r
-import java.net.Socket;\r
-\r
-// import org.umu.cops.common.COPSDebug;\r
-\r
-/**\r
- * COPS Transceiver\r
- *\r
- * @version COPSTransceiver.java, v 1.00 2003\r
- *\r
- */\r
-public class COPSTransceiver {\r
-\r
- /**\r
- * Method sendMsg\r
- *\r
- * @param msg a COPSMsg\r
- * @param fd a Socket\r
- *\r
- * @throws IOException\r
- * @throws COPSException\r
- *\r
- */\r
- static public void sendMsg(COPSMsg msg, Socket fd) throws IOException, COPSException {\r
- // COPSDebug.out("COPSTransceiver", "sendMsg ******************************** START" );\r
-\r
- msg.checkSanity();\r
- msg.writeData(fd);\r
-\r
- // COPSDebug.out("COPSTransceiver", "sendMsg ******************************** END" );\r
- }\r
-\r
- /**\r
- * Method receiveMsg\r
- *\r
- * @param fd a Socket\r
- *\r
- * @return a COPSMsg\r
- *\r
- * @throws IOException\r
- * @throws COPSException\r
- *\r
- */\r
- static public COPSMsg receiveMsg (Socket fd) throws IOException, COPSException {\r
- int nread = 0;\r
- byte[] hBuf = new byte[8];\r
-\r
- // COPSDebug.out("COPSTransceiver", "receiveMsg ******************************** START" );\r
-\r
- nread = COPSUtil.readData(fd, hBuf, 8);\r
-\r
- if (nread == 0) {\r
- throw new COPSException("Error reading connection");\r
- }\r
-\r
- if (nread != 8) {\r
- throw new COPSException("Bad COPS message");\r
- }\r
-\r
- COPSHeader hdr = new COPSHeader(hBuf);\r
- int dataLen = hdr.getMsgLength() - hdr.getHdrLength();\r
- // COPSDebug.out("COPSTransceiver", "COPS Msg length :[" + dataLen + "]\n" );\r
- byte[] buf = new byte[dataLen + 1];\r
- nread = 0;\r
-\r
- nread = COPSUtil.readData(fd, buf, dataLen);\r
- buf[dataLen] = (byte) '\0';\r
- // COPSDebug.out("COPSTransceiver", "Data read length:[" + nread + "]\n");\r
-\r
- if (nread != dataLen) {\r
- throw new COPSException("Bad COPS message");\r
- }\r
-\r
- COPSMsgParser prser = new COPSMsgParser();\r
- COPSMsg msg = prser.parse(hdr, buf);\r
-\r
- // COPSDebug.out("COPSTransceiver", "Message received");\r
-\r
- // COPSDebug.out("COPSTransceiver", "receiveMsg ******************************** END" );\r
- return msg;\r
- }\r
-}\r
-\r