Show
Ignore:
Timestamp:
03/30/09 21:38:53 (15 years ago)
Author:
trnewman
Message:

Added libvtcross functionality. Made socketcomm a little more robust. Added libvtcross demo application to illustrate how to use the lib.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/lib/socketcomm/socketcomm.cpp

    r219 r222  
    4141    // Messages are termination with a "\0" to denote EOM. 
    4242    ssize_t msgLength = recv(socketFD, msgBuffer, 256, MSG_PEEK); 
     43    if (msgLength < 0) 
     44        ERROR(1, "Error reading from socket.\n"); 
     45    if (msgLength == 0) 
     46        ERROR(1, "Remote component closed connection.\n"); 
    4347 
    4448    size_t i; 
     
    5155    msgLength = recv(socketFD, msgBuffer, i + 1, 0); 
    5256    if (msgLength < 0) 
    53         ERROR(1, "Error reading from socket"); 
     57        ERROR(1, "Error reading from socket.\n"); 
     58    if (msgLength == 0) 
     59        ERROR(1, "Remote component closed connection.\n"); 
    5460} 
    5561 
     
    6672    server = gethostbyname(serverName); 
    6773    if(server == NULL) 
    68         ERROR(1, "No server found by that hostname."); 
     74        ERROR(1, "No server found by that hostname.\n"); 
    6975 
    7076    portNumber = atoi(serverPort); 
     
    7278    socketFD = socket(AF_INET, SOCK_STREAM, 0); 
    7379    if(socketFD < 0)  
    74         ERROR(1, "Error opening socket"); 
     80        ERROR(1, "Error opening socket\n"); 
    7581 
    7682    memset((void *) &serv_addr, 0, sizeof(serv_addr)); 
     
    8187 
    8288    if(connect(socketFD, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)  
    83         ERROR(1, "Error connecting to remote socket."); 
     89        ERROR(1, "Error connecting to remote socket.\n"); 
    8490 
    8591    return socketFD; 
     
    117123{ 
    118124    ssize_t numSentBytes = send(socketFD, message, (strlen(message) + 1), 0); 
    119     if(numSentBytes < 0) { 
    120         ERROR(1, "Error sending to server."); 
     125        if(numSentBytes < 0) { 
     126        ERROR(1, "Error sending to server.\n"); 
    121127    } 
    122128    else if(numSentBytes == 0) { 
     
    210216    int32_t clientSocket = accept(serverSock, NULL, NULL); 
    211217    if(clientSocket < 0) {  
    212         WARNING("ALERT: Could not establish connection with client socket.\n"); 
     218        //WARNING("ALERT: Could not establish connection with client socket.\n"); 
    213219        return -1; 
    214220    }