c++ - Winsock looping until host comes online -
i have client wants (from time-to-time) connect remote host send messages , disconnect. host might not available. how set loop (preferably avoiding constant cpu-time-consuming loops):
attempt_send_data(data data)
is host online? no: check 1 time again yes: connect, transmit info , disconnect, return
(i using c++ , winsock2 , tcp protocol)
on totally unrelated note, since working on when deleted other question, post here, , deleted have had time take @ it.
for other readers, yes, off-topic question, maybe need messaging scheme of sort.
for starters, refactor getintersection
:
# homecoming 2, 3 or 4 items, depending on position def getintersection(x,y,grid): intersections = [] if y > 0: intersections.append((x, y - 1)) if y < grid[1] - 1: intersections.append((x, y + 1)) if x > 0: intersections.append((x - 1, y)) if x < grid[0] - 1: intersections.append((x + 1, y)) homecoming intersections
use so:
intersect = getintersection(x,y,grid) # uniform choice, hence probability expected 1/2, 1/3 or 1/4 x,y=random.choice(intersect)
c++ winsock
No comments:
Post a Comment