CMakeified almost everything. Test code in python/ and apps other than uhd_modes.py still need minor updating.
This commit is contained in:
52
python/modes_raw_server.py
Normal file
52
python/modes_raw_server.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# Copyright 2010 Nick Foster
|
||||
#
|
||||
# This file is part of gr-air-modes
|
||||
#
|
||||
# gr-air-modes is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# gr-air-modes is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with gr-air-modes; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
|
||||
import time, os, sys, socket
|
||||
from string import split, join
|
||||
from datetime import *
|
||||
|
||||
class modes_raw_server:
|
||||
def __init__(self):
|
||||
self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self._s.bind(('', 9988))
|
||||
self._s.listen(1)
|
||||
self._s.setblocking(0) #nonblocking
|
||||
self._conns = [] #list of active connections
|
||||
|
||||
def __del__(self):
|
||||
self._s.close()
|
||||
|
||||
def output(self, msg):
|
||||
for conn in self._conns[:]: #iterate over a copy of the list
|
||||
try:
|
||||
conn.send(msg)
|
||||
except socket.error:
|
||||
self._conns.remove(conn)
|
||||
print "Connections: ", len(self._conns)
|
||||
|
||||
def add_pending_conns(self):
|
||||
try:
|
||||
conn, addr = self._s.accept()
|
||||
self._conns.append(conn)
|
||||
print "Connections: ", len(self._conns)
|
||||
except socket.error:
|
||||
pass
|
||||
Reference in New Issue
Block a user