socket programming (browser) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: socket programming (browser) (/thread-14649.html) |
socket programming (browser) - kunz - Dec-10-2018 i would like to make a small application to write a name and then display in reverse order but this should use raw sockets in python making the input and output in a browser i don't even know where to begin cant find any good references if some one could just start me off RE: socket programming (browser) - snippsat - Dec-11-2018 (Dec-10-2018, 08:11 PM)kunz Wrote: but this should use raw sockets in python making the input and output in a browserFor web-development raw sockect would be a nightmare to work with. A short history CGI was bad for Python regarding the future of web-development in Python, and all Python solution's was work out WSGI(PEP 3333). Why is WSGI necessary? So to day all web-framework is build on this standard eg Flask,Django...ect. Example with Flask. form_test\ |-- app.py templates\ |-- index.htm app.py: from flask import Flask, render_template, request, redirect, url_for app = Flask(__name__) @app.route('/') def index(): return render_template("index.html") @app.route('/text', methods=['GET', 'POST']) def text(comments=[]): if request.method == "GET": return render_template("index.html", comments=comments) value = request.form["text_input"] comments.append(value[::-1] ) return redirect(url_for('text')) if __name__ == '__main__': app.run(debug=True) index.html: <!doctype html> <html> <head> <title>Some title</title> <link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/style1.css') }}" /> </head> <body> <h2>Form</h2> <form action="/text" method="post"> Input text:<br> <input type="text" name="text_input" value=""> <br> <input type="submit" value="Submit"> </form> <div id='foo'> <br> {% for comment in comments %} <div class="row"> {{ comment }} </div> {% endfor %} </div> </body> </html> RE: socket programming (browser) - kunz - Dec-11-2018 i don't want to use a library please that is the requirement i have to work with raw sockets RE: socket programming (browser) - buran - Dec-11-2018 Is this a homework/assignment in which case it should be in Homeworks RE: socket programming (browser) - snippsat - Dec-11-2018 Can look at this for a start Let’s Build A Web Server. Part 1. If it homework it's not an easy task. RE: socket programming (browser) - wavic - Dec-11-2018 For such a simple app you could try out bottle.py too. RE: socket programming (browser) - snippsat - Dec-11-2018 (Dec-11-2018, 09:27 AM)wavic Wrote: For such a simple app you could try out bottle.py too.If he can not Flask,then neither can he use bottle. With only use of raw socket,so is this not an easy task at all. RE: socket programming (browser) - wavic - Dec-11-2018 (Dec-11-2018, 10:00 AM)snippsat Wrote:Oh, I see it now. Well, he is likely to write a new web framework? Not an easy task.(Dec-11-2018, 09:27 AM)wavic Wrote: For such a simple app you could try out bottle.py too.If he can not Flask,then neither can he use bottle. RE: socket programming (browser) - siripriya - Dec-18-2018 import socket def client_program(): host = socket.gethostname() # as both code is running on same pc port = 5000 # socket server port number client_socket = socket.socket() # instantiate client_socket.connect((host, port)) # connect to the server message = input(" -> ") # take input while message.lower().strip() != 'bye': client_socket.send(message.encode()) # send message data = client_socket.recv(1024).decode() # receive response print('Received from server: ' + data) # show in terminal message = input(" -> ") # again take input client_socket.close() # close the connection if __name__ == '__main__': client_program() |