problem on socket programming

M

MalC0de

hello there, I'm using Learning Python 3rd edition as my core
reference, the book is great.
here's some snippet for demonstrating echo-server program, but I can't
interpret it in both windows / Gnu linux ...

#!/usr/bin/env python
from socket import *
myHost = ''
myPort = 50007
sockobj = socket(AF_INET,SOCK_STREAM)
sockobj.bind((myHost,myPort))
sockobj.listen(5)
while true :
connection,address = sockobj.accept()
print 'server connected by :',address
while True:
data = connection.recv(1024)
if not data: break
connection.send('echo : '+ data)
connection.close()

where's the problem,
beforehand appreciate ...
 
M

MalC0de

problem with this code solved in win32, but I didn't test it after
solved problem on gnu/linux .
 
M

MalC0de

now I've been encountered to some errors with this snippet :

import sys
from socket import *
serverHost = 'localhost'
serverPort = 50007
message = ['Hello network world']
if len(sys.argv) > 1:
serverHost = sys.argv[1]
if len(sys.argv) > 2:
message = sys.argv[2:]
sockobj = socket(AF_INET,SOCK_STREAM)
sockobj.connect((serverHost,serverPort))
for line in message:
sockobj.send(line)
data = sockobj.recv(1024)
print 'Client recieved :',repr(data)
sockobj.close()


thanks if someone can solve my problem .

- malc0de.
 
M

MalC0de

And these errors are? Provide error messages and full tracebacks.

Cheers,
Chris
--http://blog.rebertia.com

these are errors :

Traceback (most recent call last):
File "echo-client.py", line 11, in <module
sockobj.connect((serverHost,serverPort))
File "<string>", line 1, in connect
socket.error: (10061, 'Connection refused')
 
P

Piet van Oostrum

M> these are errors :
M> Traceback (most recent call last):
M> File "echo-client.py", line 11, in <module
M> sockobj.connect((serverHost,serverPort))
M> File "<string>", line 1, in connect
M> socket.error: (10061, 'Connection refused')

Is your server running?
 
D

Diez B. Roggisch

MalC0de said:
these are errors :

Traceback (most recent call last):
File "echo-client.py", line 11, in <module
sockobj.connect((serverHost,serverPort))
File "<string>", line 1, in connect
socket.error: (10061, 'Connection refused')

Can you ping and telnet to the port on the desired server? Firewalls can
be an issue here.

Diez
 
D

Diez B. Roggisch

MalC0de said:
these are errors :

Traceback (most recent call last):
File "echo-client.py", line 11, in <module
sockobj.connect((serverHost,serverPort))
File "<string>", line 1, in connect
socket.error: (10061, 'Connection refused')

Can you ping and telnet to the port on the desired server? Firewalls can
be an issue here.

Diez
 
M

MalC0de

you want to say shall i disable the firewall, there's no specific
firewall or IPS/IDS system out there, this is just windows xp firewall
 
D

Diez B. Roggisch

MalC0de said:
you want to say shall i disable the firewall, there's no specific
firewall or IPS/IDS system out there, this is just windows xp firewall

Which is a firewall, don't you agree? So it could well be the reason for
the problems you see.

Diez
 
M

MalC0de

no, I disabled my firewall, no problem with even enabled firewall ...
no one can help !?
 
M

MRAB

MalC0de said:
no, I disabled my firewall, no problem with even enabled firewall ...
no one can help !?

I hope you disconnected your computer from the internet before disabling
the firewall...
 
P

Processor-Dev1l

no, I disabled my firewall, no problem with even enabled firewall ...
no one can help !?

Connection refused... connection was refused by the listening socket,
it could also be due to the settings of your service, if it accepts
only from localhost to localhost (127.0.0.1 to 127.0.0.1) then other
connections will not be granted. Try to find some socket samples on
python.org (there are plenty of tip and tricks for using sockets)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top