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
Harbor Registry
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fernando Erd
CanguruChatServer
Commits
27459546
Commit
27459546
authored
8 years ago
by
Fernando Erd
Browse files
Options
Downloads
Patches
Plain Diff
Queue is working
parent
c603e864
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Canguru/CanguruChat.py
+18
-18
18 additions, 18 deletions
Canguru/CanguruChat.py
with
18 additions
and
18 deletions
Canguru/CanguruChat.py
+
18
−
18
View file @
27459546
...
@@ -31,10 +31,13 @@ import threading
...
@@ -31,10 +31,13 @@ import threading
import
sys
import
sys
import
binascii
import
binascii
import
time
import
time
import
Queue
global
TOKEN
global
TOKEN
global
StartTime
global
StartTime
global
HighPriority
StartTime
=
0
StartTime
=
0
HighPriority
=
10
TOKEN
=
0
TOKEN
=
0
MACHINE_ID
=
1
MACHINE_ID
=
1
SEND_PORT
=
5000
# Porta que o Servidor envia
SEND_PORT
=
5000
# Porta que o Servidor envia
...
@@ -69,7 +72,7 @@ class Protocol():
...
@@ -69,7 +72,7 @@ class Protocol():
print
'
Entrada Invalida, Por favor escolha entre 1 a 7
'
print
'
Entrada Invalida, Por favor escolha entre 1 a 7
'
sys
.
stdout
.
write
(
'
Prioridade:
'
)
sys
.
stdout
.
write
(
'
Prioridade:
'
)
self
.
priority
=
raw_input
()
self
.
priority
=
raw_input
()
self
.
priority
=
str
(
self
.
priority
)
self
.
priority
=
7
-
int
(
self
.
priority
)
def
setType
(
self
):
def
setType
(
self
):
if
(
self
.
msg
==
'
token
'
):
if
(
self
.
msg
==
'
token
'
):
...
@@ -93,7 +96,7 @@ class Protocol():
...
@@ -93,7 +96,7 @@ class Protocol():
self
.
crc
=
"
%08X
"
%
buff
self
.
crc
=
"
%08X
"
%
buff
def
getEmpacotar
(
self
):
def
getEmpacotar
(
self
):
return
self
.
marca
+
self
.
type
+
self
.
destiny
+
self
.
origin
+
self
.
priority
+
self
.
sizemsg
+
self
.
marca
+
self
.
msg
+
self
.
marca
+
self
.
crc
return
self
.
marca
+
self
.
type
+
self
.
destiny
+
self
.
origin
+
str
(
self
.
priority
)
+
self
.
sizemsg
+
self
.
marca
+
self
.
msg
+
self
.
marca
+
self
.
crc
def
setDesempacota
(
self
,
msg
):
def
setDesempacota
(
self
,
msg
):
self
.
marca
=
msg
[
0
]
self
.
marca
=
msg
[
0
]
...
@@ -118,7 +121,7 @@ def token ():
...
@@ -118,7 +121,7 @@ def token ():
while
True
:
while
True
:
EndTime
=
time
.
time
()
EndTime
=
time
.
time
()
if
(
EndTime
-
StartTime
>=
10
and
TOKEN
==
1
):
if
(
EndTime
-
StartTime
>=
10
and
TOKEN
==
1
):
print
'
Vou mandar o token
'
print
'
MANDEI O TOKEN
'
TOKEN
=
0
TOKEN
=
0
tokenMessage
.
Type
=
str
(
0
)
tokenMessage
.
Type
=
str
(
0
)
msg
=
tokenMessage
.
getEmpacotar
()
msg
=
tokenMessage
.
getEmpacotar
()
...
@@ -126,29 +129,28 @@ def token ():
...
@@ -126,29 +129,28 @@ def token ():
udp
.
close
()
udp
.
close
()
def
client
():
def
client
():
global
TOKEN
try
:
try
:
global
TOKEN
global
HighPriority
udp
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
udp
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
dest
=
(
HOST
,
SEND_PORT
)
dest
=
(
HOST
,
SEND_PORT
)
print
'
Para sair digite exit
\n
'
protocolMessage
=
Protocol
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setPriority
()
protocolMessage
.
setMessage
()
protocolMessage
.
setType
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
getEmpacotar
()
while
protocolMessage
.
msg
<>
'
exit
'
:
udp
.
sendto
(
msg
,
dest
)
protocolMessage
=
Protocol
()
protocolMessage
=
Protocol
()
queue
=
Queue
.
PriorityQueue
()
while
True
:
protocolMessage
.
setDestiny
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setPriority
()
protocolMessage
.
setPriority
()
protocolMessage
.
setMessage
()
protocolMessage
.
setMessage
()
protocolMessage
.
set
Type
(
)
protocolMessage
.
Type
=
str
(
1
)
protocolMessage
.
setSizeof
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setCRC32
()
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
getEmpacotar
()
msg
=
protocolMessage
.
getEmpacotar
()
queue
.
put
((
protocolMessage
.
priority
,
msg
))
print
queue
.
queue
HighPriority
=
queue
.
queue
[
0
]
print
HighPriority
[
0
]
if
(
TOKEN
==
1
):
print
'
POSSO ENVIAR MSG
'
#udp.sendto (msg, dest)
threadServer
.
_Thread__stop
()
threadServer
.
_Thread__stop
()
threadToken
.
_Thread__stop
()
threadToken
.
_Thread__stop
()
udp
.
close
()
udp
.
close
()
...
@@ -166,9 +168,7 @@ def server ():
...
@@ -166,9 +168,7 @@ def server ():
protocolDescompactMessage
=
Protocol
()
protocolDescompactMessage
=
Protocol
()
while
True
:
while
True
:
msg
,
cliente
=
udp
.
recvfrom
(
1024
)
msg
,
cliente
=
udp
.
recvfrom
(
1024
)
print
msg
protocolDescompactMessage
.
setDesempacota
(
msg
)
protocolDescompactMessage
.
setDesempacota
(
msg
)
print
protocolDescompactMessage
.
type
if
(
protocolDescompactMessage
.
type
==
'
0
'
and
TOKEN
==
0
):
if
(
protocolDescompactMessage
.
type
==
'
0
'
and
TOKEN
==
0
):
print
'
RECEBI O TOKEN
'
print
'
RECEBI O TOKEN
'
TOKEN
=
1
TOKEN
=
1
...
...
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