Python TCP server experiences issues when running over the internet

I stumbled upon this tutorial to learn more about TCP and networking. I successfully tested the code on localhost, but encountered an issue when trying it with my real IP address. My friend attempted to run the client on his system, but we kept getting the error message:

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

It's worth mentioning that I am using Ubuntu while my friend is on Windows.

server.py

import socket

HOST = 'my ip'
PORT = 65432

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data)

client.py

import socket

HOST = '86.184.147.101'
PORT = 65432

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(b'Hello, world')
    data = s.recv(1024)

print('Received', repr(data))

I believe there might be a simple solution to this issue, but so far I haven't been able to find any help on platforms like StackOverflow. Any advice would be greatly appreciated! Cheers!

Answer №1

Make sure to test your ability to communicate with the server by using the ping command. Review the DNATing rule for both your computer and server. Additionally, ensure that your firewall permissions are set to allow connections from other devices.

Answer №2

If you're having trouble accessing your server, it could be due to port forwarding not being set up on your home router or firewall. Ensure that port 65432 is being forwarded to your local computer where the server is running. Look up instructions for configuring port forwarding specific to your router model by searching "port forwarding" and the name of your router.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Customize Nova.conf in Devstack by configuring it in the local.conf file

I am currently utilizing Devstack in my development setup. When it comes to adding specific configuration settings in the nova.conf file, one can employ the following code snippet: [[post-config|$NOVA_CONF]] [DEFAULT] notification_driver=messagingv2 noti ...

Can R code, including packages from cran and github, be executed within a Python environment?

Currently, I am tackling a project that involves utilizing a Github package in R with Python. As such, I am on the hunt for a tool or package that can facilitate the running and installation of R codes and packages (both from CRAN and GitHub) within Pyth ...

invoking the rsync command using subprocess.call in Python

I am facing an issue while trying to run rsync over ssh from a subprocess in my python script to transfer images from one server to another. The function I have defined is: def transferBookContent(bookIds, serverEnv): bookPaths = "" if len(bookIds) ...

Steps for converting a number from any number system to the decimal system by rewriting a function from C++ to Python

I am facing an issue where I have a function in C++ that converts a number from any number system to decimal. However, I now require a similar function in Python and I am unsure how to rewrite it to function properly in Python without using built-in functi ...

Error with Ng-Repeat displaying incorrect data when deployed on Heroku

After creating a Django app that hosts data and a login, the user interacts with an Angular app inside Django upon logging in. Everything works perfectly on my local machine, but there's a strange issue on the Heroku-hosted app. A specific ng-repeat i ...

Significant gap observed between title and plot in matplotlib

I am facing an issue with matplotlib where the plot appears very far from the title. Here is my code snippet: df = pandas.read_csv(csvpath, delimiter=',', index_col=0, parse_dates=[0], dayfirst=True, ...

Python code to conduct a test for deleting data from a MongoDB

Having trouble with mongo? After running my automation tests, I need to delete all the data and objects I created. I wrote a script to do this by deleting rows from multiple tables. However, when I try to run the script, it doesn't start. What could b ...

How can I generate a PDF file directly from byte data in Python without having to write it to a binary file first?

This Python code retrieves data from a database table and converts it into a PDF file without saving it to disk, then displays it in the browser. l_statement = "select srno,attachment from dbo.attachments where srno = 1" sqlcursor.execute(l_stat ...

Waiting for elements to be loaded in Selenium and Python: A step-by-step guide

Imagine I am choosing with the following selector: //img[@data-blabla] If I want to wait for 10 elements to be loaded, not just one, how should this be altered? My assumption is to use the index [9] WebDriverWait(browser, 5).until(EC.presence_of_element_l ...

Typical process of going through a list

Transitioning from Excel to Python, I am in need of help with finding the average for a list but for each new item. Consider the list below: x = [-3.2, 2.7, -8.5, -1.4] I initially attempted the following code: avg = sum(col)/len(col) This method resul ...

Is there a way to calculate the percentile of a column in a dataframe by only taking into account the values that came before

I have a dataset containing numerical values in a column and I want to calculate the percentile of each value based on only the preceding rows in that same column. Here's an example: +-------+ | col_1 | +-------+ | 5 | +-------+ | 4 | +------- ...

Split Data Frame in Python

As a new user of Jupiter Notebook, I am facing a challenge and seeking help for the following case: I have a dataframe with 177 rows consisting of Country Names and Number of Bookings (total of two columns) see image here My goal is to create a bar chart ...

Adjusting the parameters of my support vector machine (SVM) classifier trained on a sample of the MNIST digit dataset does not seem to have any impact on the accuracy of

Being a novice in the realm of machine learning, I am currently delving into the realm of hyperparameters for an SVM with the goal of achieving at least 95% accuracy on the mnist digit dataset. The csv file being utilized by the code contains 784 attribut ...

I am encountering difficulties with searching inside elements using Python Selenium

Struggling to find elements inside another element, the expected functionality is not there. I am dealing with a table where I need to iterate and update records if a certain cell in a row is empty. I have a list of web elements to go through for iteratio ...

Symbol not defined within the lapack library of Scipy

After setting up a virtual environment on my server and installing the scipy package using the pip install command, I encountered an issue when running my optimization function. An error message showed up saying ImportError: /data/home/pxu/ve/lib/python2.7 ...

Data obtained from the server includes JSON objects along with quotes and regular expressions

While analyzing the functionality of a search page server through element inspection, it was observed that requests are sent via POST with JSON parameters. To verify this observation, I recreated the same POST request using Insomnia with identical paramete ...

What is the best way to access a specific line in a text file using Python?

I possess a text file containing specific data Style="light mode" Tone="Red" My intention is to extract the value of Style from the text file using Python, which in this case is "light mode" with open("nxc.txt","r&qu ...

Translating data between Python and MATLAB by decoding binary files

I am encountering a significant issue with the struct.unpack function in Python. I have a binary file that follows a specific format, which can be written either in MATLAB or Python. When I write data to a binary file in Python and read it back, everythin ...

Updating Dataframe Column Names using a List of New Column Names

I'm dealing with a dataframe that has numerous columns. My goal is to convert a select group of the column names to uppercase. However, my attempts at using code to accomplish this have been unsuccessful so far: df[cols_to_cap].columns = df[cols_to_ca ...

Extracting data from websites using Python's Selenium module, focusing on dynamic links generated through Javascript

Currently, I am in the process of developing a webcrawler using Selenium and Python. However, I have encountered an issue that needs to be addressed. The crawler functions by identifying all links with ListlinkerHref = self.browser.find_elements_by_xpath( ...