PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
sdl/PlatformNetwork.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/devices/PNetwork.h
4// Purpose: Class for handling network communication (tcpip)
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2006-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PLATFORM_NETWORK_H__
28#define __PLATFORM_NETWORK_H__
29
30
31#if defined(PEBL_NETWORK)
32
33#if defined(PEBL_OSX)
34#include "SDL.h"
35#include "SDL_net.h"
36#else
37#include "SDL.h"
38#include "SDL_net.h"
39#endif
40#include "../../devices/PNetwork.h"
41
42class PlatformNetwork: public PNetwork
43{
44
45public:
46
47
50
52 virtual ~PlatformNetwork();
53
54
55 virtual void Init();
56
57 virtual void SetHostIP(unsigned int);
58 virtual void SetPort(unsigned int);
59 virtual void SetHostName(std::string hostname);
60
61 // virtual void RetrievePeerIPAddress();
62 virtual Variant GetMyIPAddress();
63 virtual Variant GetIPAddress();
64
65
66 virtual void Open();
67 virtual bool CheckForConnection();
68 virtual bool CreateListener();
69 virtual bool Accept(int mstimeout);
70 virtual bool Accept();
71 virtual void Close();
72
73
74 virtual bool SendString(std::string message);
75 virtual bool SendByte(int byte);
76
77 virtual std::string Receive(int length);
78
79
80protected:
81
82
83 virtual Variant ConvertAddress(IPaddress* address);
84
85 //Inheritable printing Method.
86 virtual std::ostream& SendToStream(std::ostream& out)const;
87
88private:
89
90
91 //pointer to a TCPSocket object used by SDL_net.
92 IPaddress * mAddress; //Address I'm connected to
93 IPaddress * mMyAddress; //My address (if known)
94 TCPsocket mSocket;
95 TCPsocket mListener; //Listening socket
96
97
98};
99
100#endif
101#endif
virtual void SetHostIP(unsigned int host)
Definition PNetwork.cpp:81
virtual Variant ConvertAddress(unsigned long int address)
Definition PNetwork.cpp:57
virtual void SetHostName(std::string hostname)
Definition PNetwork.cpp:97
virtual void SetPort(unsigned int port)
Definition PNetwork.cpp:108
virtual std::ostream & SendToStream(std::ostream &out) const
Variant GetMyIPAddress(Variant v)
Variant GetIPAddress(Variant v)