source: flair-src/trunk/lib/FlairCore/src/TcpSocket.h@ 12

Last change on this file since 12 was 2, checked in by Sanahuja Guillaume, 9 years ago

flaircore

File size: 1.7 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5/*!
6 * \file TcpSocket.h
7 * \brief Class defining a Tcp socket
8 * \author Gildas Bayard, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2015/04/28
10 * \version 4.0
11 */
12
13#ifndef TCPSOCKET_H
14#define TCPSOCKET_H
15
16#include <ConnectedSocket.h>
17
18namespace flair
19{
20namespace core
21{
22 /*! \class TcpSocket
23 *
24 * \brief Class encapsulating a TCP socket
25 *
26 */
27 class TcpSocket:public ConnectedSocket {
28 public:
29 TcpSocket(const Object* parent,const std::string name,bool blockOnSend=false,bool blockOnReceive=true);
30 ~TcpSocket();
31 void Listen(const unsigned int port,const std::string localAddress="ANY");
32 TcpSocket *Accept(Time timeout=0); //should throw an exception if not a listening socket
33 bool Connect(const unsigned int distantPort,const std::string distantAddress,Time timeout=0); // timeout in milliseconds
34 ssize_t SendMessage(const char* message,size_t message_len,Time timeout=0); // timeout in milliseconds
35 ssize_t RecvMessage(char* buf,size_t buf_len,Time timeout=0); // timeout in milliseconds
36
37 uint16_t NetworkToHost16(uint16_t data);
38 uint16_t HostToNetwork16(uint16_t data);
39 uint32_t NetworkToHost32(uint32_t data);
40 uint32_t HostToNetwork32(uint32_t data);
41
42 private:
43 int socket; // socket file descriptor
44 bool blockOnSend;
45 bool blockOnReceive;
46 bool isConnected;
47 unsigned int distantPort;
48 std::string distantAddress;
49 };
50
51} // end namespace core
52} // end namespace flair
53
54#endif // TCPSOCKET_H
Note: See TracBrowser for help on using the repository browser.