j.smith1981 Posted November 4, 2011 Share Posted November 4, 2011 Hi there, I have been having a go at creating a socket server in Python and I am a bit stuck, here's my code: # Created by: Jeremy Smith # Date: 04/11/2011 @ 16:54 # Illustration taken from: http://effbot.org/librarybook/socket.htm ## Firstly we import the much needed libs: import socket import struct, time # Now define the port no the clients will need to connect to (need to open this port on any NAT or Software based Firewall): PORT = 8045; # so will technically be like http://192.168.0.2:8045 if it was a http server! # Now create the socket and get it listening on that port: service = socket.socket(socket.AF_INET, socket.SOCK_STREAM) service.bind(("", PORT)) service.listen(1) print "Socket has been created and is listening on port: ", PORT while 1: # while true? channel, info = service.accept() print "Received a connection from: ", info # can i just put in literals within the send method? channel.send() channel.close() The problem I am having is understanding what I can put in the send method, can I just send any thing like in PHP you can use to send things like "server is alive or something", which would become something along the lines of: channel.send("server is alive") Or am I thinking about this the wrong way completely? Any help is much appreciated, Jeremy. Link to comment https://forums.phpfreaks.com/topic/250449-python-socket-server-question/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.