-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
102 lines (79 loc) · 3 KB
/
server.py
File metadata and controls
102 lines (79 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'''
This program 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 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
Created on May 22, 2011
@author: Alexandre Prates
'''
import socket
from streamSpdy import Pack, unpack
from heapq import heappush, heappop
import thread
class Server():
sock = None
def __init__(self, port):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.bind(('',port))
self.sock.setblocking(0)
def tcpConn(self):
self.sock.listen(1)
(sockaddr, cli) = self.sock.accept()
return (sockaddr, cli)
def send(self,cli, data):
cli.send(data)
def rec(self, cli):
data = cli.recv(1024)
return data
def close(self):
thread.exit_thread()
self.close()
class SPDYServer():
#implementar threadS
__versions = []
__SETTINGS_UPLOAD_BANDWIDTH = 0
__SETTINGS_DOWNLOAD_BANDWIDTH = 0
__SETTINGS_ROUND_TRIP_TIME = 0
__SETTINGS_MAX_CONCURRENT_STREAMS = 0
__SETTINGS_CURRENT_CWND = 0
__stream = [] #list of priority stream
__bufferstream={} #stream active
idstream = 2
def run(self):
conn = Server(8000)
conn.tcpConn()
thread.start_new_thread(receive, conn)
def receive(self, conn):
while True:
data = conn.rec()
frame = unpack(data)
if not(frame['streamID'] in self.__bufferstream):#receiver new stream
if (frame['control']==1):
if(frame['type']==1):
if(frame['streamID']%2==1):
heappush(self.__stream, [frame['priority'], frame['streamID']])
self.__bufferstream[frame['streamID']] = 1
elif (frame['type']==3):
del self.__bufferstream[frame['streamID']]
for i in self.__stream:
if i[1]==frame['streamID']:
self.__stream.remove(i)
elif (frame['type']==8):
del self.__bufferstream
del self.__stream
conn.close()
elif (frame['control']==0):
if not(frame['streamID'] in self.__bufferstream):
#eception
#exception
a= Server(8006)
print "porta aberta"
(s, c) = a.tcpConn()
a.send(s, 'teste')
print a.rec(s)