-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added socket server, modified SocketClientPlot and readme
- Loading branch information
Suyash458
committed
Aug 1, 2016
1 parent
f428f63
commit a69c6f0
Showing
3 changed files
with
47 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from SoftOscilloscope import SocketClientPlot | ||
|
||
class SocketServer(asyncore.dispatcher): | ||
def __init__(self, address, num_clients=5, **kwargs): | ||
asyncore.dispatcher.__init__(self) | ||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) | ||
self.bind(address) | ||
self.listen(num_clients) | ||
|
||
def handle_accept(self): | ||
client, addr = self.accept() | ||
print "Connected to " + str(addr) | ||
SocketClientPlot(socket=client, address=addr).start() | ||
|
||
def handle_close(self): | ||
self.close() | ||
print "Closing server." | ||
|
||
def run_server(): | ||
address = ('0.0.0.0',5000) | ||
server = SocketServer(address) | ||
try: | ||
print "Server listening on " + str(address) | ||
asyncore.loop(0.2, use_poll = True) | ||
except KeyboardInterrupt: | ||
print "Closing server." | ||
server.close() |