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

  • Home
  • SEARCH
  • 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 8063351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:00:06+00:00 2026-06-05T11:00:06+00:00

So far I have been able to work out a basic socket in python

  • 0

So far I have been able to work out a basic socket in python 3.2. The client sends some data, an X and a Y coordinate, to the server, and the server takes the data and sends back a confirmation message. But the trouble I’m having is getting it to listen between computers. My server and client work perfect when I run them side-by-side on the same computer, but I want to get them to connect while running on different computers.

I have one computer upstairs, and one computer downstairs, both using the same wireless internet. Is there a way I can connect my server and client from one of each of these computers?

I have already tried changing the server IP to the IP address of my wireless modem, but that did not work.

Here is my code so far, the only difference is I changed the IP address back to a standard loop-back address, since just changing it to my IP did not work:

Client:

import pygame, sys
from socket import socket, AF_INET, SOCK_DGRAM
from time import gmtime, strftime
from pygame.locals import *

SERVER_IP   = '127.0.0.1'
PORT_NUMBER = 5000
SCREEN_X = 400
SCREEN_Y = 400
SIZE = 1024
PIC_PATH = "picture/path/goes/here.bmp"
print ("Test client sending packets to IP {0}, via port {1}\n".format(SERVER_IP, PORT_NUMBER))

mySocket = socket( AF_INET, SOCK_DGRAM )
x = y = 0
screen = pygame.display.set_mode((SCREEN_X, SCREEN_Y)) #Make the screen
ending = False
word = "True"
clock = pygame.time.Clock() #tick-tock
grid = pygame.image.load(PIC_PATH) #Load the sheet
gridRect = grid.get_rect()
screen.blit(grid, gridRect)
pygame.display.flip()
while ending==False:
    for event in pygame.event.get():
        if event.type == KEYDOWN: # key down or up?
            if event.key == K_RIGHT: x+=1
            elif event.key == K_LEFT: x-=1
            elif event.key == K_UP: y-=1
            elif event.key == K_DOWN: y+=1
            if event.key == K_ESCAPE:
                ending=True # Time to leave
                print("Stopped Early by user")
    if ending==True: word="False"
    localTime = strftime( "%H:%M:%S", gmtime() )
    mySocket.sendto( bytes(str(x), 'UTF-8') , (SERVER_IP, PORT_NUMBER) )
    mySocket.sendto( bytes(str(y), 'UTF-8') , (SERVER_IP, PORT_NUMBER) )
    mySocket.sendto( bytes(word, 'UTF-8') , (SERVER_IP, PORT_NUMBER) )
    print ("Sending packet... " + localTime)
    clock.tick(10)
    try:
        (data, addr) = mySocket.recvfrom( SIZE )
        print ("Received packet from: " + str(addr))
        print ("Received: " + data.decode('UTF-8'))
    except: ending=False
    if ending==True:
        pygame.quit()
        sys.exit()

Server:

from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
PORT_NUMBER = 5000
SIZE = 1024

hostName = gethostbyname( 'localhost' )

mySocket = socket( AF_INET, SOCK_DGRAM )
mySocket.bind( (hostName, PORT_NUMBER) )

print ("Test server listening on port {0}\n".format(PORT_NUMBER))

flag="True"

while flag=="True":
    #Show that data was received:
    (data, addr) = mySocket.recvfrom( SIZE )
    xer=data.decode('UTF-8')
    print ("Received packet from: " + str(addr) + ", X value:" + str(xer))
    (data, addr) = mySocket.recvfrom( SIZE )
    yer=data.decode('UTF-8')
    print ("Received packet from: " + str(addr) + ", Y value:" + str(yer))
    #Check to see if the other program wants to close:
    (flagger, addr) = mySocket.recvfrom( SIZE )
    flag=flagger.decode('UTF-8')
    #Send a message back to the client:
    if flag=="False": s="Good-bye!"
    else: s="Read you loud and clear"
    mySocket.sendto( bytes(s, 'UTF-8') , (addr) )
sys.exit()

Just in case you’re wondering why the client is so big, it’s because I’m trying to make a little game in pygame that will be multi-player. Not internet but LAN or wireless between my two computers.
I am very new to sockets and web related stuff (I don’t know if LAN is basically the same as wireless or what) so any help on this is greatly appreciated. 🙂

  • 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-05T11:00:09+00:00Added an answer on June 5, 2026 at 11:00 am

    Don’t bind to localhost. This means that your server will only listen to itself. If you bind to 0.0.0.0, this will ensure that your server is listening to every computer that can reach it. (Warning: potentially insecure.)

    An overzealous firewall rule could also be to blame.

    Make sure you are connecting to your server’s IP in your router’s subnet. To do so, run ifconfig on Mac/Linux or ipconfig on Windows, which will probably show you a 192.168.x.x-style IP (which will not be the same as your router’s IP). You can also see what computers and IPs are connected to your router via its administrative page.

    At any given point in time, a computer that is connected to the Internet has many IPs. The loop-back address is only ‘visible’ to your computer. An IP like 10.x.x.x or 192.168.x.x would be visible to any computers connected to your router. Most other IPs are public IPs.

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

Sidebar

Related Questions

So far I have not been able to find an answer, but I wanted
So far the only way I have been able to keep index.yaml updated when
I'm trying to achieve the following: So far, I have been able to do
I'm trying to install bcrypt-ruby on Windows Vista. So far, I have been able
So I have been looking every where, and so far i haven't been able
I've been given some strings to work with. Each one represents a data set
As far as I've been able to find out, Windows doesn't offer an API
I have been pondering writing this question for quite some time. I work for
i have been looking around to try and work out how to pass 2
So far I have been creating Web Portal but recently I had a request

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.