Closed Thread
Results 1 to 5 of 5

Thread: Sockets

  1. #1
    psam is offline Learning Programmer
    Join Date
    Jun 2009
    Posts
    34
    Rep Power
    10

    Sockets

    I'm new to sockets so i tried to write a code using them in order to retrieve the html code of a page and i got this:

    Code:
    import socket
    mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    mySocket.connect(("forum.codecall.net", 80))
    mySocket.send("GET / HTTP/1.1\n")
    mySocket.send("Host: forum.codecall.net\n\n\n")
    text = mySocket.recv(1024)
    print text
    This doesn't work well. I know how to do it using urllib but i wanted to understand sockets. Can anyone help me?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    CallBackGuy is offline Newbie
    Join Date
    Mar 2009
    Posts
    29
    Rep Power
    0

    Re: Sockets

    Code:
    import socket
    mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    mySocket.connect(("forum.codecall.net", 80))
    mySocket.send("GET / HTTP/1.1\n")
    mySocket.send("Host: forum.codecall.net\n\n")
    text = ''
    
    while 1:
        data = mySocket.recv(1024)
        text += data
        if not data: break
        
    mySocket.close()
    
    print text

  4. #3
    Tyson.S is offline Newbie
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Re: Sockets

    Im new to the whole sockets to, actually i never knew you could obtain html code through sockets on python , but it looks all good.

  5. #4
    kiddies is offline Programmer
    Join Date
    May 2009
    Posts
    129
    Rep Power
    0

    Re: Sockets

    Code:
    while 1:
        data = mySocket.recv(1024)
        text += data
        if not data: break
        
    mySocket.close()
    what for this...

  6. #5
    psam is offline Learning Programmer
    Join Date
    Jun 2009
    Posts
    34
    Rep Power
    10

    Re: Sockets

    Nice =). Thank you very much for your help. I thought the html of the page would all be sent on only one time.
    P.S.:I'm sorry for the late answer but i haven't been online in a while.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C++ Sockets
    By AuraDevil in forum C and C++
    Replies: 3
    Last Post: 04-15-2010, 05:58 AM
  2. Help with Sockets!
    By so1i in forum Visual Basic Programming
    Replies: 2
    Last Post: 10-12-2009, 01:16 AM
  3. C++ Sockets
    By Khaotic in forum C and C++
    Replies: 3
    Last Post: 04-28-2009, 06:35 PM
  4. TCP/IP Sockets?
    By Dyroxide in forum Visual Basic Programming
    Replies: 1
    Last Post: 03-15-2009, 03:31 PM
  5. Sockets
    By mastersjw in forum Java Help
    Replies: 2
    Last Post: 01-29-2007, 12:42 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts