VTK  9.1.0
vtkSocket.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSocket.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
23#ifndef vtkSocket_h
24#define vtkSocket_h
25
26#include "vtkCommonSystemModule.h" // For export macro
27#include "vtkObject.h"
28
30class VTKCOMMONSYSTEM_EXPORT vtkSocket : public vtkObject
31{
32public:
33 vtkTypeMacro(vtkSocket, vtkObject);
34 void PrintSelf(ostream& os, vtkIndent indent) override;
35
36 // ----- Status API ----
40 int GetConnected() { return (this->SocketDescriptor >= 0); }
41
46
47 // ------ Communication API ---
52 int Send(const void* data, int length);
53
62 int Receive(void* data, int length, int readFully = 1);
63
68 vtkGetMacro(SocketDescriptor, int);
69
75 static int SelectSockets(
76 const int* sockets_to_select, int size, unsigned long msec, int* selected_index);
77
78protected:
80 ~vtkSocket() override;
81
83
84 friend class vtkSocketCollection;
85
91
95 void CloseSocket(int socketdescriptor);
96
101 int BindSocket(int socketdescriptor, int port);
102
108 int SelectSocket(int socketdescriptor, unsigned long msec);
109
114 int Accept(int socketdescriptor);
115
119 int Listen(int socketdescriptor);
120
124 int Connect(int socketdescriptor, const char* hostname, int port);
125
130 int GetPort(int socketdescriptor);
131
132private:
133 vtkSocket(const vtkSocket&) = delete;
134 void operator=(const vtkSocket&) = delete;
135};
136
137#endif
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:82
a collection for sockets.
BSD socket encapsulation.
Definition: vtkSocket.h:31
void CloseSocket()
Close the socket.
int CreateSocket()
Creates an endpoint for communication and returns the descriptor.
static int SelectSockets(const int *sockets_to_select, int size, unsigned long msec, int *selected_index)
Selects set of sockets.
int Accept(int socketdescriptor)
Accept a connection on a socket.
int SelectSocket(int socketdescriptor, unsigned long msec)
Selects a socket ie.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Listen(int socketdescriptor)
Listen for connections on a socket.
int GetConnected()
Check is the socket is alive.
Definition: vtkSocket.h:40
void CloseSocket(int socketdescriptor)
Close the socket.
int BindSocket(int socketdescriptor, int port)
Binds socket to a particular port.
int GetPort(int socketdescriptor)
Returns the port to which the socket is connected.
~vtkSocket() override
int SocketDescriptor
Definition: vtkSocket.h:82
int Connect(int socketdescriptor, const char *hostname, int port)
Connect to a server socket.
int Receive(void *data, int length, int readFully=1)
Receive data from the socket.
int Send(const void *data, int length)
These methods send data over the socket.