Are you willing to connect with 127.0.0.1:62893 via Pyhton? Well here you go, I have shared complete script in this post.
Before we begin (Keep In Consideration):
Port 62893 is in the dynamic/private port range (49152-65535). This suggests it’s likely a temporary port assigned by your system for a specific application or service.
To use these scripts:
- Save them as two separate files:
server.pyandclient.py - First run the server script in one terminal: bashCopy
python server.py - Then run the client script in another terminal: bashCopy
python client.py
# server.py - Run this on the listening side
import socket
def start_server():
# Create a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind to localhost and the specified port
host = '127.0.0.1'
port = 62893
server_socket.bind((host, port))
# Listen for incoming connections
server_socket.listen(1)
print(f"Server listening on {host}:{port}")
while True:
# Accept incoming connection
client_socket, address = server_socket.accept()
print(f"Connection from {address}")
# Receive data from client
data = client_socket.recv(1024).decode()
print(f"Received: {data}")
# Send response back to client
response = "Message received!"
client_socket.send(response.encode())
client_socket.close()
if __name__ == "__main__":
start_server()
# client.py - Run this to connect to the server
import socket
def start_client():
# Create a socket object
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to the server
host = '127.0.0.1'
port = 62893
try:
client_socket.connect((host, port))
print(f"Connected to {host}:{port}")
# Send message to server
message = "Hello, Server!"
client_socket.send(message.encode())
# Receive response from server
response = client_socket.recv(1024).decode()
print(f"Server response: {response}")
except ConnectionRefusedError:
print("Connection failed - make sure the server is running")
finally:
client_socket.close()
if __name__ == "__main__":
start_client()
To run these socket scripts in PyCharm, you don’t need to install any additional libraries since the socket module is part of Python’s standard library. It comes built-in with Python.
For more advanced features, you might want:
pip install requests # For HTTP requests
pip install paramiko # For SSH connections
