web server python
# Creating a Web server using Python and Flask
from flask import Flask
app = Flask('app')
@app.route('/')
def run():
return '<h1>Hello, Server!</h1>'
app.run(host = '0.0.0.0', port = 8080)
web server python
# Creating a Web server using Python and Flask
from flask import Flask
app = Flask('app')
@app.route('/')
def run():
return '<h1>Hello, Server!</h1>'
app.run(host = '0.0.0.0', port = 8080)
python how to make a server
#server
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1234))#the 1234 is the server ip that client is going to connect to.
s.listen(5)
while True:
clientsocket, Address = s.accept()
print(f'IP Address [{Address}] has connect to the server')#this is what the server will show when the client connect to the server.
clientsocket.send(bytes("hi", "utf-8" ))#this is what the client will be showen.
clientsocket.close()
#---------------------------------------------------------------
#client
#this code needs to be in a diffenet file
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((socket.gethostname(), 1234))#the 1234 is the server ip the client is connecting to.
full_msg = ''
while True:
msg = s.recv(8)
if len(msg) <= 0:
break
full_msg += msg.decode("utf-8")
print(msg.decode("utf-8"))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us