summaryrefslogtreecommitdiffstats
path: root/kenolaba/Network.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /kenolaba/Network.h
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kenolaba/Network.h')
-rw-r--r--kenolaba/Network.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/kenolaba/Network.h b/kenolaba/Network.h
new file mode 100644
index 00000000..d5251cc6
--- /dev/null
+++ b/kenolaba/Network.h
@@ -0,0 +1,60 @@
+/*
+ * Simple Network Support
+ * Install a listening socket; receive positions on incoming
+ * connections (incoming positions are treated as if pasted in)
+ */
+
+#ifndef _NETWORK_H_
+#define _NETWORK_H_
+
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#include <qobject.h>
+#include <qptrlist.h>
+#include <qsocketnotifier.h>
+
+class Listener {
+ public:
+ Listener(const char*,int,struct sockaddr_in,bool=true);
+
+ char host[100];
+ int port;
+ struct sockaddr_in sin;
+ bool reachable;
+};
+
+
+class Network: public QObject
+{
+ Q_OBJECT
+
+ public:
+ enum { defaultPort = 23412 };
+
+ /* install listening TCP socket on port */
+ Network(int port = defaultPort);
+ ~Network();
+
+ bool isOK() { return (fd>=0); }
+ void addListener(const char* host, int port);
+ void broadcast(const char* pos);
+
+ signals:
+ void gotPosition(const char* pos);
+
+ private slots:
+ void gotConnection();
+
+ private:
+ bool sendString(struct sockaddr_in sin, char* str, int len);
+
+ QPtrList<Listener> listeners;
+ struct sockaddr_in mySin;
+ int fd, myPort;
+ QSocketNotifier *sn;
+};
+
+#endif
+
+