Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9074431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:38:04+00:00 2026-06-16T18:38:04+00:00

I am trying to connect to my raspberry pi over the network. I’m running

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:38:05+00:00Added an answer on June 16, 2026 at 6:38 pm

    I think the problem is that you’re using socket.gethostname() which will return the hostname and not the ip. Most probably this means that your socket will bind to that hostname but not the IP, this means that python will only listen to connections to the hostname which probably is: raspberrypi

    Most probably your machines does not know about that hostname, so you want to use this instead:

    socket.gethostbyname(socket.gethostname())
    

    Which it also says in the documentation

    The thing to remember is that hostname and IP is not the same thing.
    However you could bind your hostname to the IP that you have in the /etc/hosts file like this:

    192.168.1.247 raspberrypi

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'am trying to connect to a remote server over ssh2 using the lib ch.ethz.ssh2.Connection
When I am trying to connect to my SVN repository on some remote server
I am trying to connect to a MySQL Server using JDBC tool in java
Trying to connect to sql server 2005 with delphi 2010 gives me the following
im trying to connect mysql in android app. Below is my code. Once i
When trying to connect to EC2 over SSH I get the following error: joshua-scotts-macbook-pro:.ec2
Trying to connect to a SQL Server 2005 instance remotely but getting the following
I am trying to connect to SQL Server 2008 using JDBC. My SQL Server
I am trying to connect to my rabbitmq server. I am using require 'carrot'
I am trying to connect to localhost in IIS7 on Windows server 2003 R2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.