Link to home
Start Free TrialLog in
Avatar of Dolamite Jenkins
Dolamite JenkinsFlag for United States of America

asked on

socket.error: [Errno 10061] No connection could be made because the target machine actively refused it\par

Sockets Cant Connect Over Lan so reading the forum I need to get the host name

Traceback (most recent call last):
  File "c:\Python26\network folder\server_side_xxx.py", line 13, in <module>
    addr = (gethostbyname(gethostname()), port)
NameError: name 'gethostbyname' is not defined

Open in new window


I've disable the firewall
1.this  the server side code and addr = gethostbyname() iis causeing the error
2. do I have to get the the hostbyname on the client side too ?
3. Is there anything else Im missing
import socket

host = ''
port = 50000
backlog = 5
size = 1024
addr = (gethostname(), port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((addr))
s.listen(backlog)
while 1:
    client, address = s.accept()
    data = client.recv(size)
    if data:
        client.send(data)
    client.close() 

Open in new window


client side

import sqlite3 
import sqlite3 as lite
import socket


host = 'localhost'
port = 50000
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
f = open('ban.txt', "r")
data2 = f.read()
f.close()
s.connect((host,port))
s.send(data)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of -Richard-
-Richard-
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In case it wasn't completely clear, the second form of import allows you to drop the qualifier from references to any method in the socket library; the first form is specific only to the gethostname method.
Avatar of Dolamite Jenkins

ASKER

do I need to do that on the client side too ?
im still getting the error on the client side

Traceback (most recent call last):
  File "c:\Python26\network folder\client_side_xxx.py", line 22, in <module>
    s.connect((host,port))
  File "<string>", line 1, in connect
socket.error: [Errno 10061] No connection could be made because the target machine actively refused it
Process terminated with an exit code of 1

Open in new window


import sqlite3
import sqlite3 as lite
import socket


host = 'localhost'
port = 50000
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
f = open('ban.txt', "r")
data2 = f.read()
f.close()
s.connect((host,port))
s.send(data)

Open in new window

Thanks