source: trunk/packages/vizservers/nanovis/socket/ClientSocket.cpp @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/* ======================================================================
3 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
4 *           Purdue Rendering and Perceptualization Lab (PURPL)
5 *
6 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
7 *
8 *  See the file "license.terms" for information on usage and
9 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 * ======================================================================
11 */
12#include "ClientSocket.h"
13#include "SocketException.h"
14
15ClientSocket::ClientSocket(std::string host, int port)
16{
17    if (!Socket::create()) {
18        throw SocketException("Could not create client socket.");
19    }
20
21    if (!Socket::connect(host, port)) {
22        throw SocketException("Could not bind to port.");
23    }
24}
25
26const ClientSocket& ClientSocket::operator <<(const std::string& s) const
27{
28    if (!Socket::send(s)) {
29        throw SocketException("Could not write to socket.");
30    }
31
32    return *this;
33}
34
35const ClientSocket& ClientSocket::operator >>(std::string& s) const
36{
37    if (!Socket::recv(s)) {
38        throw SocketException("Could not read from socket.");
39    }
40
41    return *this;
42}
43
44void ClientSocket::set_non_blocking(bool val)
45{
46    Socket::set_non_blocking(val);
47}
48
49bool ClientSocket::send(char* s, int size) const
50{
51    bool ret = Socket::send(s, size);
52    if (!ret) {
53        throw SocketException("Could not write to socket.");
54    }
55
56    return ret;
57}
58
59int ClientSocket::recv(char *s, int size) const
60{
61    bool ret = Socket::recv (s, size);
62    if (!ret) {
63        throw SocketException("Could not read from socket.");
64    }
65
66    return ret;
67}
Note: See TracBrowser for help on using the repository browser.