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
93b5c08e
Commit
93b5c08e
authored
8 years ago
by
FernandoErd
Browse files
Options
Downloads
Patches
Plain Diff
Protocol maybe working
parent
197ac74b
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/Cliente.py
+69
-64
69 additions, 64 deletions
Canguru/Cliente.py
with
69 additions
and
64 deletions
Canguru/Cliente.py
+
69
−
64
View file @
93b5c08e
#!/usr/bin/env python
#################### Protocol #############################
# Marca - Destino - Prioridade - Tamamnho - Messagem - CRC#
###########################################################
#################### Protocol ######################################
# Marca - Destino - Origem - Prioridade - Tamamnho - Menssagem - CRC#
####################################################################
#Marca - 1 Byte
#Destino - 4 Bytes
#Origem - 4 Bytes
#Prioridade - 4 Bytes
#Tamanho - 32 bytes
#Menssagem - ??
#CRC - 4 bytes
import
socket
import
threading
...
...
@@ -21,62 +29,60 @@ class FuncThread(threading.Thread):
def
run
(
self
):
self
.
_target
(
*
self
.
_args
)
class
Protocol
()
:
def
__init__
(
):
class
Protocol
:
def
getMarca
(
self
):
self
.
marca
=
"
~
"
#Marca
#Get sizeof message
def
sizeof
(
self
,
msg
):
self
.
sizemsg
=
sys
.
getsizeof
(
msg
)
print
self
.
sizemsg
#Get destiny message
def
get
d
estiny
():
def
get
D
estiny
(
self
):
print
'
Destino:
'
self
.
destiny
=
raw_input
()
self
.
destiny
=
str
(
self
.
destiny
)
def
getOrigin
(
self
):
self
.
origin
=
"
1
"
#Get Priority messsage
def
getPriority
():
def
getPriority
(
self
):
print
'
Prioridade:
'
self
.
priority
=
raw_input
()
self
.
priority
=
str
(
self
.
priority
)
#Get message
def
getMessage
():
def
getMessage
(
self
):
print
'
Mensagem:
'
self
.
msg
=
raw_input
()
#def empacotar():
# return self.marca + self.sizemsg
#Get sizeof message
def
getSizeof
(
self
):
self
.
sizemsg
=
sys
.
getsizeof
(
self
.
msg
)
self
.
sizemsg
=
str
(
self
.
sizemsg
)
#String convert
print
self
.
sizemsg
#Get CRC32
def
getCRC32
(
msg
):
buff
=
(
binascii
.
crc32
(
msg
)
&
0xFFFFFFFF
)
return
"
%08X
"
%
buff
class
queue
(
object
):
def
__init__
(
self
):
self
.
dados
=
[]
def
insere
(
self
,
elemento
):
self
.
dados
.
append
(
elemento
)
def
retira
(
self
):
return
self
.
dados
.
pop
(
0
)
def
vazia
(
self
):
return
len
(
self
.
dados
)
==
0
def
getCRC32
(
self
):
buff
=
(
binascii
.
crc32
(
self
.
msg
)
&
0xFFFFFFFF
)
self
.
crc
=
"
%08X
"
%
buff
def
empacotar
(
self
):
return
self
.
marca
+
self
.
destiny
+
self
.
origin
+
self
.
priority
+
self
.
sizemsg
+
self
.
msg
+
self
.
crc
def
client
():
udp
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_DGRAM
)
dest
=
(
HOST
,
SEND_PORT
)
print
'
Para sair digite exit
\n
'
print
'
Mensagem:
'
msg
=
raw_input
()
hostname
=
socket
.
gethostname
()
# Pega o hostname
while
msg
<>
'
exit
'
:
hostname
=
socket
.
gethostname
()
protocolMessage
=
Protocol
()
protocolMessage
.
getMarca
()
protocolMessage
.
getDestiny
()
protocolMessage
.
getOrigin
()
protocolMessage
.
getPriority
()
protocolMessage
.
getMessage
()
protocolMessage
.
getSizeof
()
protocolMessage
.
getCRC32
()
msg
=
protocolMessage
.
empacotar
()
while
True
:
udp
.
sendto
(
hostname
,
dest
)
# Envia Hostname
udp
.
sendto
(
msg
,
dest
)
#Envia Mensagem
print
'
Mensagem:
'
...
...
@@ -106,5 +112,4 @@ if len(sys.argv) > 1:
threadServer
=
FuncThread
(
server
)
threadServer
.
start
()
threadClient
=
FuncThread
(
client
)
threadClient
.
start
()
client
()
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