Socket error

Socket error

Postby Kickalot » Sun Jul 10, 2016 2:00 am

Hey guys! I'm new here so excuse the newbyness :P

Basically I have just started to learn python, getting into it I started to learn networking. SO I am using this book violent python by T J O Conner

I am just on the introduction and have ALREADY bumped into an error (I know I said I'm a newb but not that much of a newb with programming as I know a bit about python)

Code: Select all
Traceback (most recent call last):
  File "", line 7, in <module>
    s.connect(("", 21))
  File "/usr/lib/python2.7/", line 228, in meth
    return getattr
socket.timeout: timed out

I cannot find anything on google, have tried to change the port, tried to set the timeout to 10 and even tried cancelling it out with # entirely.

this is the code :

Code: Select all
import socket

= socket.socket()
s.connect(("", 80))
ans = s.recv(1024)
print ans

any help is appreciated! thanks
Last edited by micseydel on Sun Jul 10, 2016 2:01 am, edited 1 time in total.
Reason: Code tags. Initial post lock.
Posts: 1
Joined: Sun Jul 10, 2016 1:56 am

Re: Socket error

Postby Loophole_ » Sun Jul 10, 2016 6:44 am

First of all, I would like to know which kind of socket you are creating(client or server) ??

But whenever you are dealing with sockets, you need to define the type of socket you are using, BEFORE you continue with other processes(binding, listening, etc)

replace the code :
Code: Select all
s = socket . socket()

in your program with

Code: Select all
s = socket . socket(
socket.AF_INET, socket . SOCK_STREAM)

and then restructure your program. A flowchart might be very useful.
Posts: 29
Joined: Tue May 24, 2016 4:58 pm

Return to Networking

Who is online

Users browsing this forum: No registered users and 2 guests