I'm having some issues with this python client. I'd appreciate it if someone could tell me what's wrong.
import socket, sys, time, os
host = '155.94.243.10'
port = 80
mySocket = socket.socket()
mySocket.connect((host,port))
message = input('>>>')
while message != 'q':
mySocket.send(message.encode())
data = mySocket.recv(1024).decode()
print('Received from server: ' + str(data))
message = input('>>>')
mySocket.close()
I'm using "GET / HTTP/1.1" as the input.
I get no response from the server, I should be getting an error message (I think)
Edit: I used wireshark to confirm I am connecting to the server.
Thanks in advance.
asked Nov 12, 2016 at 3:46
Eli Richardson
9409 silver badges25 bronze badges
1 Answer 1
Client has to send empty line aftera all headers. It inform server that it get all headers and it can send response (or it has to read body if you send POST).
import socket
import sys
import time
import os
#host = '155.94.243.10'
host = 'stackoverflow.com'
port = 80
mySocket = socket.socket()
mySocket.connect((host,port))
message = input('>>>')
while message != 'q':
message += '\n\n'
#message = 'GET / HTTP/1.1\n\n'
mySocket.send(message.encode())
data = mySocket.recv(1024).decode()
print('Received from server: ' + str(data))
message = input('>>>')
mySocket.close()
EDIT: It seems '155.94.243.10' needs other headers to get result. Try
message = 'GET / HTTP/1.1\nHost: 155.94.243.10\n\n'
answered Nov 12, 2016 at 4:11
furas
149k12 gold badges121 silver badges171 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Eli Richardson
Thank you, I was trying to add the newlines in with the input.
lang-py
"GET / HTTP/1.1\n\n". Now serwer is waiting for new line.