Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket with if-loops does not give a consistent result #37

Open
rahul6612 opened this issue Mar 9, 2019 · 1 comment
Open

Socket with if-loops does not give a consistent result #37

rahul6612 opened this issue Mar 9, 2019 · 1 comment

Comments

@rahul6612
Copy link

rahul6612 commented Mar 9, 2019

The program is continuously receiving data from the sender side. And I have a checked/unchecked button when I make it checked it runs the if part...that's good. Now I make it unchecked then else part runs and prints Unchecked going to close socket, so that's also good.

The problem is when I am going to make it again checked (2nd time) to run if part again it just print Checked and my program hangs. Why is this happening? It should receive the data but it hangs. Please tell me the solution.

def show_markers(self):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    host = socket.gethostbyname('192.168.225.12')
    s.connect((host, port))
    scale=0

    while True:

        if self.iconAction.isChecked():
            print ('Checked')
            m = QgsVertexMarker(self.iface.mapCanvas())
            data = s.recv(SIZE)
            data1 = s.recv(SIZE)
            c = data.decode()
            d = data1.decode()
            x = float(c)
            y = float(d)
            print("printing X :", x)
            print("printing Y :", y)
            rect = QgsRectangle(float(x)-scale, float(y)-scale, float(x)+scale, float(y)+scale)
            me = self.iface.mapCanvas()
            me.setExtent(rect)
            me.refresh()
            m.setCenter(QgsPointXY(x, y))
            m.setColor(QColor(255, 0, 0))
            m.setIconSize(7)
            m.setIconType(QgsVertexMarker.ICON_X)  # or ICON_CROSS, ICON_X
            m.setPenWidth(3)

        else:
            print('Unchecked going to close socket')
            s.shutdown(10)
            s.close()

I am assuming it should work like:

  1. 1st time click on button ---> Checked & if part run [working]
  2. 2nd time click on button ---> Unchecked & else part run [working]
  3. 3rd time click on button ---> again it Checked [here it checked but my program hangs & not receiving the data from sender computer]
@shashi278
Copy link

@rahul6612 I guess your assumption is correct. The server will wait for the responses from client and hence will hang if neither data is sent nor the connection is closed.
And I think this issue should be closed by now as it's not an issue with the repo's code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants