AGX Dynamics  2.35.0.1
SocketTrack.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 #pragma once
17 
18 #include <agxData/FrameIO.h>
19 #include <agxNet/Socket.h>
20 #include <agxNet/FramePacket.h>
21 #include <agx/Json.h>
22 
23 
24 
25 namespace agxNet
26 {
32  {
33  public:
34 
39 
40  /*
41  * Use this constructor when you already have a socket you want to send frames through.
42  */
44 
45  virtual void writeFrame(const agxData::Frame* frame);
46 
47  virtual void endOfStream();
48 
49  agx::UInt16 getPort() const;
50  protected:
52 
53  private:
54  void acceptIncommingConnectionRequests();
55  void sendPacket(agxNet::FramePacket *packet, agxNet::TCPSocket* socket);
56  void sendPadding(size_t numBytes, agxNet::TCPSocket* socket);
57 
58  private:
59  agx::UInt16 m_port;
60  agxNet::TCPServerSocketRef m_serverSocket;
61  agxNet::TCPSocketRefVector m_clientSockets;
62  };
63 
64 
65 
68  {
69  public:
72 
73  virtual agxData::Frame* readFrame();
74 
75  virtual bool jumpToFrame(agx::UInt frameIndex);
76 
77  protected:
78  virtual ~TcpSocketFrameReader() {}
79 
80  private:
81  bool readHeader();
82  size_t sumBufferSizes(agxJson::Value& header);
83  void readPadding(size_t padding);
84 
85  private:
86  agxNet::TCPSocketRef m_socket;
87  agxJson::Value m_nextHeader;
88  agxData::BinaryDataRef m_binarySegment;
89  StructuredMessage::PreHeader m_preHeader;
90 
91  bool m_isValid;
92  };
93 
94 
96  AGX_FORCE_INLINE bool TcpSocketFrameReader::jumpToFrame(agx::UInt /*frameIndex*/) { return false; }
98 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXCORE_EXPORT
The FrameReader reads frames from an external source.
Definition: FrameIO.h:127
The FrameWriter writes frames to an external target.
Definition: FrameIO.h:169
a structure which holds IP address
Definition: Socket.h:117
TcpSocketFrameReader(agxNet::TCPSocket *socket)
virtual agxData::Frame * readFrame()
Reads the next frame from the stream and moves the stream forward one frame.
virtual bool jumpToFrame(agx::UInt frameIndex)
Select which frame that should be returned by the next call to 'readFrame'.
Definition: SocketTrack.h:96
TcpSocketFrameReader(agxNet::IPAddress address)
agx::UInt16 getPort() const
Definition: SocketTrack.h:97
TcpSocketFrameWriter(agx::UInt16 port)
Use this constructor when you want the TcpSocketFrameWriter to open a server socket.
TcpSocketFrameWriter(agxNet::TCPSocket *socket)
virtual void writeFrame(const agxData::Frame *frame)
#define AGX_FORCE_INLINE
Definition: macros.h:58
Containins classes for sending/reading data over sockets as well as compression functionality.
Definition: MacUtil.h:23
uint16_t UInt16
Definition: Integer.h:39
uint32_t UInt
Definition: Integer.h:34