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
, but s.shutdown(10)
& s.close()
not closing the socket it shows the error s.shutdown(10) is not a socket object OS [Errno 10022] an invalid argument is supplied Why its not closing the socket or is there other any way to close it.
Additional Requirement
if my socket get closed again i want to make it checked (2nd time) to run if
part again to receive data from sender computer is it possible to start socket again without closing my program.
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:
1st time click on button ---> Checked & if part run [working]
2nd time click on button ---> Unchecked & else part run to close the socket [not closing]
3rd time click on button ---> again it Checked and receive data from sender computer [is it possible]