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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fernando Erd
CanguruChatServer
Commits
0537c3e1
Commit
0537c3e1
authored
8 years ago
by
Fernando Erd
Browse files
Options
Downloads
Patches
Plain Diff
Modulates the code
parent
8cf84fd6
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
Canguru/Cliente.py
+38
-36
38 additions, 36 deletions
Canguru/Cliente.py
with
38 additions
and
36 deletions
Canguru/Cliente.py
+
38
−
36
View file @
0537c3e1
...
...
@@ -20,6 +20,7 @@ import binascii
HOST
=
"
127.0.0.1
"
# Endereco IP do Servidor
SEND_PORT
=
5000
# Porta que o Servidor envia
RECV_PORT
=
5001
# Porta que o Servidor recebe
MACHINE_ID
=
1
class
FuncThread
(
threading
.
Thread
):
def
__init__
(
self
,
tarset
,
*
args
):
...
...
@@ -30,9 +31,15 @@ class FuncThread(threading.Thread):
def
run
(
self
):
self
.
_tarset
(
*
self
.
_args
)
class
Protocol
:
def
setMarca
(
self
):
class
Protocol
()
:
def
__init__
(
self
):
self
.
marca
=
"
~
"
#Marca
self
.
destiny
=
None
self
.
origin
=
str
(
MACHINE_ID
)
self
.
priority
=
None
self
.
msg
=
None
self
.
sizemsg
=
None
self
.
crc
=
None
#set destiny message
def
setDestiny
(
self
):
...
...
@@ -40,9 +47,6 @@ class Protocol:
self
.
destiny
=
raw_input
()
self
.
destiny
=
str
(
self
.
destiny
)
def
setOrigin
(
self
):
self
.
origin
=
"
1
"
#set Priority messsage
def
setPriority
(
self
):
print
'
Prioridade:
'
...
...
@@ -65,7 +69,7 @@ class Protocol:
buff
=
(
binascii
.
crc32
(
self
.
msg
)
&
0xFFFFFFFF
)
self
.
crc
=
"
%08X
"
%
buff
def
e
mpacotar
(
self
):
def
getE
mpacotar
(
self
):
return
self
.
marca
+
self
.
destiny
+
self
.
origin
+
self
.
priority
+
self
.
marca
+
self
.
sizemsg
+
self
.
msg
+
self
.
crc
def
desempacota
(
self
,
msg
):
...
...
@@ -81,30 +85,27 @@ def client ():
dest
=
(
HOST
,
SEND_PORT
)
print
'
Para sair digite exit
\n
'
print
'
Mensagem:
'
hostname
=
socket
.
sethostname
()
#
hostname = socket.sethostname()
protocolMessage
=
Protocol
()
protocolMessage
.
setMarca
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setOrigin
()
protocolMessage
.
setPriority
()
protocolMessage
.
setMessage
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
empacotar
()
msg
=
protocolMessage
.
getEmpacotar
()
#hostname = socket.sethostname()
while
True
:
udp
.
sendto
(
hostname
,
dest
)
# Envia Hostname
#
udp.sendto (hostname, dest) # Envia Hostname
udp
.
sendto
(
msg
,
dest
)
#Envia Mensagem
print
'
Mensagem:
'
protocolMessage
=
Protocol
()
protocolMessage
.
setMarca
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setOrigin
()
protocolMessage
.
setPriority
()
protocolMessage
.
setMessage
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
e
mpacotar
()
hostname
=
socket
.
sethostname
()
msg
=
protocolMessage
.
getE
mpacotar
()
#
hostname = socket.sethostname()
udp
.
close
()
def
server
():
...
...
@@ -113,9 +114,10 @@ def server ():
orig
=
(
HOST
,
RECV_PORT
)
udp
.
bind
(
orig
)
while
True
:
hostname
,
cliente
=
udp
.
recvfrom
(
1024
)
#
hostname, cliente = udp.recvfrom(1024)
msg
,
cliente
=
udp
.
recvfrom
(
1024
)
print
hostname
,
'
:
'
,
msg
#print hostname,':', msg
print
msg
print
'
Estou no Server
'
udp
.
close
()
...
...
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