Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CanguruChatServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fernando Erd
CanguruChatServer
Commits
ce1714e9
Commit
ce1714e9
authored
Nov 9, 2016
by
Fernando Erd
Browse files
Options
Downloads
Patches
Plain Diff
quase
parent
f7e4cdd3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
maybe.py
+8
-39
8 additions, 39 deletions
maybe.py
with
8 additions
and
39 deletions
maybe.py
+
8
−
39
View file @
ce1714e9
...
...
@@ -78,12 +78,6 @@ class Protocol():
self
.
priority
=
raw_input
()
self
.
priority
=
7
-
int
(
self
.
priority
)
def
setType
(
self
):
if
(
self
.
msg
==
'
token
'
):
self
.
type
=
str
(
0
)
else
:
self
.
type
=
str
(
1
)
#set message
def
setMessage
(
self
):
sys
.
stdout
.
write
(
'
Mensagem:
'
)
...
...
@@ -134,25 +128,17 @@ def token ():
tokenMessage
.
type
=
str
(
0
)
tokenMessage
.
priority
=
str
(
PRIORITY_TOKEN
)
msg
=
tokenMessage
.
getEmpacotar
()
print
msg
udp
.
sendto
(
msg
,
dest
)
#time.sleep(2)
if
(
not
queue
.
empty
()):
m
=
queue
.
queue
[
0
]
print
m
print
PRIORITY_TOKEN
print
m
[
0
]
print
TOKEN
if
(
int
(
PRIORITY_TOKEN
)
>=
int
(
m
[
0
])):
print
'
envie
'
queue
.
get
()
msgProtocol
.
setDesempacota
(
m
[
1
])
msgProtocol
.
priority
=
str
(
7
)
msg
=
msgProtocol
.
getEmpacotar
()
udp
.
sendto
(
msg
,
dest
)
print
'
ENVIANDO
'
time
.
sleep
(
1
)
while
(
RECEBIDA
==
0
):
print
'
ENVIANDO NOVAMENTE A MSG
'
...
...
@@ -176,8 +162,6 @@ def client ():
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
getEmpacotar
()
queue
.
put
((
protocolMessage
.
priority
,
msg
))
if
(
not
queue
.
empty
()):
HighPriority
=
queue
.
queue
[
0
]
threadServer
.
_Thread__stop
()
threadToken
.
_Thread__stop
()
except
:
...
...
@@ -201,55 +185,40 @@ def server ():
while
True
:
msg
,
cliente
=
udp
.
recvfrom
(
1024
)
protocolDescompactMessage
.
setDesempacota
(
msg
)
#print msg
#Recebi o token
print
msg
if
(
protocolDescompactMessage
.
type
==
'
1
'
and
int
(
MACHINE_ID
)
==
int
(
protocolDescompactMessage
.
origin
)):
print
'
LELELEL
'
print
'
SETANDO A PRIORIDADE
'
PRIORITY_TOKEN
=
protocolDescompactMessage
.
priority
print
PRIORITY_TOKEN
print
'
EU RECEBI A MSG QUE ENVIEI
'
elif
(
protocolDescompactMessage
.
type
==
'
0
'
and
TOKEN
==
0
):
print
'
RECEBI O TOKEN
'
TOKEN
=
1
StartTime
=
time
.
time
()
#A msg foi enviada com sucesso
elif
(
msg
[
1
]
==
'
2
'
and
int
(
MACHINE_ID
)
==
int
(
protocolDescompactMessage
.
destiny
)):
print
'
A MENSAGEM FOI ENVIADA COM SUCESSO
'
RECEBIDA
=
1
#Erro no envio
elif
(
msg
[
1
]
==
'
3
'
and
int
(
MACHINE_ID
)
==
int
(
protocolDescompactMessage
.
destiny
)):
RECEBIDA
=
0
#A msg e pra mim
elif
(
msg
[
1
]
==
'
1
'
and
int
(
MACHINE_ID
)
==
int
(
protocolDescompactMessage
.
destiny
)):
print
msg
[
4
]
#protocolDescompactMessage.crc = "8888888"#caga tdo
udp
.
sendto
(
msg
,
dest
)
if
(
protocolDescompactMessage
.
crc
==
protocolDescompactMessage
.
getCRC32
()):
print
'
\n
'
+
protocolDescompactMessage
.
origin
+
'
Escreveu:
'
+
protocolDescompactMessage
.
msg
udp
.
sendto
(
msg
,
dest
)
else
:
print
'
ERRO DE MENSAGEM
'
udp
.
sendto
(
msg
,
dest
)
#A msg n e pra mim
elif
(
msg
[
1
]
==
'
1
'
or
msg
[
2
]
==
'
2
'
or
msg
[
3
]
==
'
3
'
):
elif
(
msg
[
1
]
==
'
1
'
):
if
(
not
queue
.
empty
()):
top
=
queue
.
queue
[
0
]
HighPriorat
=
int
(
top
[
0
])
if
(
HighPriorat
<
int
(
msg
[
4
])):
print
msg
aux1
.
setDesempacota
(
msg
)
aux1
.
priority
=
str
(
HighPriorat
)
msg
=
aux1
.
getEmpacotar
()
print
msg
udp
.
sendto
(
msg
,
dest
)
udp
.
close
()
#------------------MAIN-----------------#
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment