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 8629785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:53:37+00:00 2026-06-12T08:53:37+00:00

Instead of returning the values in an infinite loop from the server, I want

  • 0

Instead of returning the values in an infinite loop from the server, I want to make a method, example getPositions() which returns the specific position that I want to while the connection server is still running. How do I do it?

import socket
import os,sys
import time

HOST = '59.191.193.59'
PORT = 5555

client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((HOST,PORT))

screen_width = 0
screen_height = 0
while True:

    client_socket.send("loc\n")
    data = client_socket.recv(8192)
    coordinates = data.split()

    if(not(coordinates[-1] == "eom" and coordinates[0] == "start")):
        continue

    if (screen_width != int(coordinates[2])):
        screen_width = int(coordinates[2])
        screen_height = int(coordinates[3])


    print int(coordinates[8])
    print int(coordinates[9])
    print int(coordinates[12])
    print int(coordinates[13])

enter image description here

  • 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-12T08:53:38+00:00Added an answer on June 12, 2026 at 8:53 am

    This should be pretty straight-forward:

    import socket
    import os,sys
    import time
    from threading import Thread
    
    HOST = '59.191.193.59'
    PORT = 5555
    
    COORDINATES = []
    
    def connect():   
        globals()['client_socket'] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client_socket.connect((HOST,PORT))
    
    def update_coordinates():
        connect()
        screen_width = 0
        screen_height = 0
        while True:
            try:
                client_socket.send("loc\n")
                data = client_socket.recv(8192)
            exept:
                connect();
                continue;
    
            globals()['COORDINATES'] = data.split()
    
            if(not(COORDINATES[-1] == "eom" and COORDINATES[0] == "start")):
                continue
    
                if (screen_width != int(COORDINATES[2])):
                    screen_width = int(COORDINATES[2])
                    screen_height = int(COORDINATES[3])            
    
    Thread(target=update_coordinates).start()
    
    // Run your controlling app here. COORDINATES will be available in the global scope and will be updated constantly
    

    EDIT: Created Method inside the get_coordinates function to re-establish socket connection in the event of a failure.

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

Sidebar

Related Questions

I'm having some issues returning values from a server with php + mysql. This
I have a DataTable in C# which I am returning from SQL server. I
The Object.clone() method in Java is pretty special, as instead of returning a copy
I am having trouble returning only checked items from a list of items. Instead
It seems like in most mainstream programming languages, returning multiple values from a function
Instead of returning a List<Long> of ids when calling PersonDao.getAll() we wanted not to
I was wondering if returning a list, instead of returning a pointer to one,
r'\' in Python does not work as expected. Instead of returning a string with
I see that most of big websites are returning javascript objects instead of pure
Instead of stepping when the user clicks somewhere on the qslider I want to

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.