I am trying to connect to my raspberry pi over the network. I'm running python as the server on the raspi. Here is the simple server code I got off the web:
import socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 80
print (host)
print (port)
serversocket.bind((host, port))
serversocket.listen(5)
print ('server started and listening')
while 1:
(clientsocket, address) = serversocket.accept()
print ("connection found!")
data = clientsocket.recv(1024).decode()
print (data)
clientsocket.send("data is sent".encode())
Test client code:
import socket
s = socket.socket()
host = "192.168.1.247"
port = 80
s.connect((host,port))
s.send('randomData'.encode())
data = ''
data = s.recv(1024).decode()
print (data)
s.close
I have tested it on other computers and these work fine. When raspi is the CLIENT and the other computer is the server it works fine. But, when raspi is SERVER and the other computer is the client, I always get the same error: "No connection could be made because the target machine actively refused it"
Trying to connect using c#:
TcpClient client = new TcpClient("192.168.1.247", 80)
throws error: "No connection could be made because the target machine actively refused it"
Note: -raspi as client to raspi as server works fine. -I have done some research and it seems that the most common causes of this is a firewall or bad router. --I don't think its the router cause I can do a raspy to other computer just fine. --I'm using the Raspbian “wheezy” Debian distro and I don't think that comes with a firewall.
Any help would be appreciated. Thanks!
iptables.