python - Socket programming, attributeerror '_socketobject' object attribute 'bind' is read-only -
i'm trying make project send messages rpi android phone using sockets , print on screen. raspberry pi acts server while android device client. code used off python website , is
import socket import sys # create tcp/ip socket server_socket = socket.socket(socket.af_inet, socket.sock_stream) server_address = ('192.168.1.108', 8080) server_socket.bind(server_address) server_socket.listen(1) while true: # find connections connection, client_address = server_socket.accept() try: data = connection.recv(1024) print data except: connection.close()
but when run on terminal window shows error "attributeerror '_socketobject' object attribute 'bind' read-only" tell me error , how resolve it.
you have hard coded ip address in there. ip address of raspberry pi. windows machine not have same ip address.
you can use special value 0.0.0.0
bind current machines ip address, whatever might be.
server_address = ('0.0.0.0', 8080)
Comments
Post a Comment