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
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
...
@@ -20,6 +20,7 @@ import binascii
HOST
=
"
127.0.0.1
"
# Endereco IP do Servidor
HOST
=
"
127.0.0.1
"
# Endereco IP do Servidor
SEND_PORT
=
5000
# Porta que o Servidor envia
SEND_PORT
=
5000
# Porta que o Servidor envia
RECV_PORT
=
5001
# Porta que o Servidor recebe
RECV_PORT
=
5001
# Porta que o Servidor recebe
MACHINE_ID
=
1
class
FuncThread
(
threading
.
Thread
):
class
FuncThread
(
threading
.
Thread
):
def
__init__
(
self
,
tarset
,
*
args
):
def
__init__
(
self
,
tarset
,
*
args
):
...
@@ -30,9 +31,15 @@ class FuncThread(threading.Thread):
...
@@ -30,9 +31,15 @@ class FuncThread(threading.Thread):
def
run
(
self
):
def
run
(
self
):
self
.
_tarset
(
*
self
.
_args
)
self
.
_tarset
(
*
self
.
_args
)
class
Protocol
:
class
Protocol
()
:
def
setMarca
(
self
):
def
__init__
(
self
):
self
.
marca
=
"
~
"
#Marca
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
#set destiny message
def
setDestiny
(
self
):
def
setDestiny
(
self
):
...
@@ -40,9 +47,6 @@ class Protocol:
...
@@ -40,9 +47,6 @@ class Protocol:
self
.
destiny
=
raw_input
()
self
.
destiny
=
raw_input
()
self
.
destiny
=
str
(
self
.
destiny
)
self
.
destiny
=
str
(
self
.
destiny
)
def
setOrigin
(
self
):
self
.
origin
=
"
1
"
#set Priority messsage
#set Priority messsage
def
setPriority
(
self
):
def
setPriority
(
self
):
print
'
Prioridade:
'
print
'
Prioridade:
'
...
@@ -65,7 +69,7 @@ class Protocol:
...
@@ -65,7 +69,7 @@ class Protocol:
buff
=
(
binascii
.
crc32
(
self
.
msg
)
&
0xFFFFFFFF
)
buff
=
(
binascii
.
crc32
(
self
.
msg
)
&
0xFFFFFFFF
)
self
.
crc
=
"
%08X
"
%
buff
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
return
self
.
marca
+
self
.
destiny
+
self
.
origin
+
self
.
priority
+
self
.
marca
+
self
.
sizemsg
+
self
.
msg
+
self
.
crc
def
desempacota
(
self
,
msg
):
def
desempacota
(
self
,
msg
):
...
@@ -81,30 +85,27 @@ def client ():
...
@@ -81,30 +85,27 @@ def client ():
dest
=
(
HOST
,
SEND_PORT
)
dest
=
(
HOST
,
SEND_PORT
)
print
'
Para sair digite exit
\n
'
print
'
Para sair digite exit
\n
'
print
'
Mensagem:
'
print
'
Mensagem:
'
hostname
=
socket
.
sethostname
()
#
hostname = socket.sethostname()
protocolMessage
=
Protocol
()
protocolMessage
=
Protocol
()
protocolMessage
.
setMarca
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setOrigin
()
protocolMessage
.
setPriority
()
protocolMessage
.
setPriority
()
protocolMessage
.
setMessage
()
protocolMessage
.
setMessage
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setCRC32
()
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
empacotar
()
msg
=
protocolMessage
.
getEmpacotar
()
#hostname = socket.sethostname()
while
True
:
while
True
:
udp
.
sendto
(
hostname
,
dest
)
# Envia Hostname
#
udp.sendto (hostname, dest) # Envia Hostname
udp
.
sendto
(
msg
,
dest
)
#Envia Mensagem
udp
.
sendto
(
msg
,
dest
)
#Envia Mensagem
print
'
Mensagem:
'
print
'
Mensagem:
'
protocolMessage
=
Protocol
()
protocolMessage
=
Protocol
()
protocolMessage
.
setMarca
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setDestiny
()
protocolMessage
.
setOrigin
()
protocolMessage
.
setPriority
()
protocolMessage
.
setPriority
()
protocolMessage
.
setMessage
()
protocolMessage
.
setMessage
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setSizeof
()
protocolMessage
.
setCRC32
()
protocolMessage
.
setCRC32
()
msg
=
protocolMessage
.
e
mpacotar
()
msg
=
protocolMessage
.
getE
mpacotar
()
hostname
=
socket
.
sethostname
()
#
hostname = socket.sethostname()
udp
.
close
()
udp
.
close
()
def
server
():
def
server
():
...
@@ -113,9 +114,10 @@ def server ():
...
@@ -113,9 +114,10 @@ def server ():
orig
=
(
HOST
,
RECV_PORT
)
orig
=
(
HOST
,
RECV_PORT
)
udp
.
bind
(
orig
)
udp
.
bind
(
orig
)
while
True
:
while
True
:
hostname
,
cliente
=
udp
.
recvfrom
(
1024
)
#
hostname, cliente = udp.recvfrom(1024)
msg
,
cliente
=
udp
.
recvfrom
(
1024
)
msg
,
cliente
=
udp
.
recvfrom
(
1024
)
print
hostname
,
'
:
'
,
msg
#print hostname,':', msg
print
msg
print
'
Estou no Server
'
print
'
Estou no Server
'
udp
.
close
()
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