By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

Server and Client Socket problem

P: n/a
Hi.

I am starting a server socket program. I send data from client socket but
the server don´t recived anything.

This is my python code:

Server:

import socket
def run():
servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
servidor.bind(('localhost', 6969))
servidor.listen(1)
while 1:
(conexion, direccion) = servidor.accept()
datos = conexion.recv(4069)
print "Servidor Recibe", datos
if datos == "quit":
servidor.close()
break

run()
Client:

import socket
def run():
cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cliente.connect(('localhost', 6969))
except:
print "No he podido Conectar con el Servidor"
return
datos = '12345678'
cliente.send(datos)
#cliente.close()

run()
I am a new python user. what can i do?

Thank you.

Regards.
José Carlos
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

import socket
def run():
servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
servidor.bind(('localhost', 6969))
servidor.listen(1)
while 1:
(conexion, direccion) = servidor.accept()
datos = conexion.recv(4069)
print "Servidor Recibe", datos
if datos == "quit":
servidor.close()
break

run()


This code can obviously not run, as its not properly indented. I'm sure that
indentation got somehow lost when you create the posting, but as long as
you don't provide it in a executable fashion, we can't help you.

However, as someone beeing recently converted from hand-made socket
programming to twisted, I suggest instead of working with sockets yourself,
you better investigate into the twisted framework. Its very well
documented.

Regards,

Diez B. Roggisch
Jul 18 '05 #2

P: n/a
> This code can obviously not run, as its not properly indented. I'm sure that
indentation got somehow lost when you create the posting, but as long as
you don't provide it in a executable fashion, we can't help you.
Agreed.
However, as someone beeing recently converted from hand-made socket
programming to twisted, I suggest instead of working with sockets yourself,
you better investigate into the twisted framework. Its very well
documented.


After having written both synchronous and asynchronous servers and
clients using Python sockets, I've been very happy with the asyncore
standard library. I should probably give twisted a shot, but writing
with asyncore is so easy that I'm hard-pressed to even bother. I also
get a sick satisfaction in implementing protocols...but maybe that is
just me.

- Josiah
Jul 18 '05 #3

P: n/a
Apart from indentation, you had forgotten the "try" statement in client
This should work better :

Client

---------------------
import socket

def run():
try:
cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cliente.connect(('localhost', 6969))
except:
print "No he podido Conectar con el Servidor"
return
datos = '12345678'
cliente.send(datos)
#cliente.close()

run()

---------------------

Server

---------------------
import socket

def run():
servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
servidor.bind(('localhost', 6969))
servidor.listen(1)
while 1:
(conexion, direccion) = servidor.accept()
datos = conexion.recv(4069)
print "Servidor Recibe", datos
if datos == "quit":
servidor.close()
break

run()
---------------------

@+
Pierre
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.