Connection refused with sockets in python -


first off, users because learnt lot reading questions , answers on website.

i'm starting learn python , i'm trying send information of pc on internet through sockets pc. worked great when connected 2 computers of localhost. however, i'm trying connect friend's computer , can't it. know (thanks previous topics on page) server needs forward port own computer. friend did and, me client , server, haven't been able connect.

i'd show simple code because i'm sure mistaken can't figure out what.

this client script:

    s = socket.socket(socket.af_inet, socket.sock_stream)     s.connect(("public ip of server",9990))  if true:     print "conexion establecida" while true:     mensaje = raw_input("mensaje enviar: ")     if mensaje == "close":         break     else:         s.send(mensaje) print "mensaje enviado." s.close() 

and server script:

import socket s = socket.socket(socket.af_inet, socket.sock_stream) s.bind(("",9990)) s.listen(1) sc, addr = s.accept() print "conexion establecida con ", str(addr[0]) while true:     recibido = sc.recv(1024)     if recibido == "close":         break     print str(addr[0]) + " dice: ", recibido         sc.close() s.close() 

the client script connect public ip server and, if true, let user send message. server scripts receives message , prints it. hope enough no not make lose lot of time. lot of reading me!


Comments