0

I have tried to send HTTP requests through TCP by connecting to a site, but I don't get any reply in return when I try to receive data from the server .

Here's my code in Python:

import socket
s = socket.socket() ; 
s.connect(('google.com' , 80)) ; 
s.send(b"GET / HTTP/1.1\r\nHost: google.com\r\n") ; 
s.recv(1024) # The program waits here infinitely meaning I haven't got a reploy from server.

What am I doing wrong? How do I get the html page using a TCP or UDP socket?

Also, since HTTP is connectionless, does it mean I should only use UDP and not TCP?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Natesh bhat
  • 12,274
  • 10
  • 84
  • 125
  • what's up with the semicolons? – President James K. Polk Jul 31 '18 at 00:11
  • 1
    HTTP is **stateless**, not **connectionless**. BIG difference. HTTP doesn't maintain any state information between requests (if a server wants that, it needs to use cookies or localstorage). Multiple HTTP requests can be sent over a single connection, or separate connections. HTTP doesn't work over UDP, you must use TCP. – Remy Lebeau Jul 31 '18 at 08:34
  • Thank you , that cleared a lot – Natesh bhat Jul 31 '18 at 12:51

0 Answers0