-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/__pycache__ | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h1 align="center"> :construction: Python Server :snake: Em construção... :construction: </h1> | ||
|
||
### Concluídos | ||
|
||
- [x] Criar um server Python | ||
- [x] Fazer o server retornar uma página Web | ||
- [x] Criar requisições GET | ||
- [ ] Criar requisições POST | ||
- [ ] Criar conexões entre cliente/servidor | ||
|
||
### Como rodar o projeto | ||
|
||
$ cmd.exe | ||
$ cd C:\Users\nomeUsuário\diretorio_do_projeto\python-server | ||
$ py main.py | ||
|
||
### Tecnologias | ||
- [Python](https://www.python.org/) | ||
- [Bootstrap](https://getbootstrap.com/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import socket | ||
|
||
class Client(): | ||
|
||
def __init__(self, address = 'localhost', port = 3000): | ||
self.address = address | ||
self.port = port | ||
|
||
def connect(self): | ||
server = (self.address, self.port) | ||
|
||
conection = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
conection.bind((self.address, self.port)) | ||
|
||
msg = input('-> ') | ||
|
||
while msg != 'closed': | ||
conection.sendto(msg.encode(), server) | ||
date, addressConection = conection.recvfrom(1024) | ||
|
||
print('received -> ', str(date)) | ||
|
||
msg = input('-> ') | ||
|
||
if __name__ == '__main__': | ||
cn = Client() | ||
cn.connect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from server import Server | ||
|
||
if __name__ == '__main__': | ||
sr = Server() | ||
sr.connect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# UDP | ||
# Protocolo que não se basea em uma conexão em que se manda dados sem segurança com relação ao seu ddestino. | ||
import socket | ||
|
||
class Server: | ||
|
||
def __init__(self, address = '', port = 3000): | ||
self.address = address | ||
self.port = port | ||
|
||
def connect(self): | ||
#Criando socket com o protocolo UDP utilizando 'SOCK_DGRAM' | ||
|
||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as server: | ||
# Bind() só recebe 1 paramentro então utilizando as (()) conseguimos burlar isso já que teoricamente é apenas 1 | ||
server.bind((self.address, self.port)) | ||
|
||
while True: | ||
print('Connecting to server') | ||
date, addressConection = server.recvfrom(1024) | ||
|
||
|
||
print('message received from: ', str(addressConection)) | ||
print('received customer: ', str(date)) | ||
|
||
response = str(date) | ||
server.sendto(date, addressConection) | ||
|
||
|
||
|
||
|
Binary file not shown.
Empty file.