Last active
November 15, 2023 11:25
-
-
Save okalachev/556cc1a9331f181311faeb3f2ad54013 to your computer and use it in GitHub Desktop.
Networking examples
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
import requests | |
r = requests.get('http://192.168.11.136:5000', params={'foo': 123}) | |
print(r.text) |
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
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route('/') | |
def hello(): | |
print(request.args) | |
return 'hello' |
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
import socket | |
import time | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect(('192.168.11.1', 7000)) | |
print('connected') | |
while True: | |
s.send('hello\n'.encode('utf-8')) | |
time.sleep(1) |
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
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind(('0.0.0.0', 7000)) | |
s.listen() | |
connection, client_address = s.accept() | |
print('connected', connection, client_address) | |
while True: | |
data = connection.recv(1000).decode('utf-8') | |
print('data: ', data) |
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
import socket | |
import time | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
while True: | |
print('send message') | |
s.sendto('hello'.encode('utf-8'), ('192.168.11.1', 6000)) | |
time.sleep(1) |
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
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
server_address = ('0.0.0.0', 6000) | |
s.bind(server_address) | |
while True: | |
data, address = s.recvfrom(4096) | |
print('data: ', data.decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment