W
webmaster
Hi,
i just try to connect to a website, read that page and display the rules get from it.
Then i get this error message:
File "D:/Python/Py projects/socket test/sockettest.py", line 21, in <module>
fileobj.write("GET "+filename+" HTTP/1.0\n\n")
io.UnsupportedOperation: not writable
My code:
# import sys for handling command line argument
# import socket for network communications
import sys, socket
# hard-wire the port number for safety's sake
# then take the names of the host and file from the command line
port = 80
host = 'www.xxxxxxxx.nl'
filename = 'index.php'
# create a socket object called 'c'
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect to the socket
c.connect((host, port))
# create a file-like object to read
fileobj = c.makefile('r', 1024)
# Ask the server for the file
fileobj.write("GET "+filename+" HTTP/1.0\n\n")
# read the lines of the file object into a buffer, buff
buff = fileobj.readlines()
# step through the buffer, printing each line
for line in buff:
print (line)
I started with invent games with python (book 1 & 2)
Now I want to write a multiplayergame, which connects to a website, where all players and gamedata will be stored/controlled.
Players need to subscribe and to login via the game software. (executable, made from python script)
Sending gamedata preferable in JSON, because of low traffic resources then.
No idea about how authentication proces should be done....
I made many searches with Google, but got confused about my first steps.
I am new to python, but code for many years in php/mysql. Spent most time in an online chessgame project.
i just try to connect to a website, read that page and display the rules get from it.
Then i get this error message:
File "D:/Python/Py projects/socket test/sockettest.py", line 21, in <module>
fileobj.write("GET "+filename+" HTTP/1.0\n\n")
io.UnsupportedOperation: not writable
My code:
# import sys for handling command line argument
# import socket for network communications
import sys, socket
# hard-wire the port number for safety's sake
# then take the names of the host and file from the command line
port = 80
host = 'www.xxxxxxxx.nl'
filename = 'index.php'
# create a socket object called 'c'
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# connect to the socket
c.connect((host, port))
# create a file-like object to read
fileobj = c.makefile('r', 1024)
# Ask the server for the file
fileobj.write("GET "+filename+" HTTP/1.0\n\n")
# read the lines of the file object into a buffer, buff
buff = fileobj.readlines()
# step through the buffer, printing each line
for line in buff:
print (line)
I started with invent games with python (book 1 & 2)
Now I want to write a multiplayergame, which connects to a website, where all players and gamedata will be stored/controlled.
Players need to subscribe and to login via the game software. (executable, made from python script)
Sending gamedata preferable in JSON, because of low traffic resources then.
No idea about how authentication proces should be done....
I made many searches with Google, but got confused about my first steps.
I am new to python, but code for many years in php/mysql. Spent most time in an online chessgame project.