Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inter-Program Data Sharing Demo (by Galleon)
#1
Code: (Select All)
SCREEN _NEWIMAGE(512, 512, 256)

DIM a(511, 511) AS INTEGER 'an array we'll send

x = _OPENCLIENT("TCP/IP:1234:localhost") 'try to connect to a host

IF x = 0 THEN '      couldn't be client, so become a host
    'put some data into array a
    FOR xx = 0 TO 511
        FOR yy = 0 TO 511
            a(xx, yy) = xx * yy
        NEXT
    NEXT
    PRINT "(Try running two copies of me at once!)"
    PRINT "Waiting... (Press any key to end)"
    x = _OPENHOST("TCP/IP:1234")
    DO
        z = _OPENCONNECTION(x)
        IF z <> 0 THEN
            PUT #z, , a() 'send array a to any client that connects
            CLOSE z
            PRINT "Array data send to client!"
        END IF
        _LIMIT 10
    LOOP UNTIL INKEY$ <> ""
    PRINT "Finished!"
    END
END IF

'connect to host as a client
PRINT "Conected to host. Reading data..."
DO
    GET #x, , a()
    _LIMIT 100
LOOP UNTIL EOF(x) = 0 'wait until enough data to fill the array arrives
FOR xx = 0 TO 511
    FOR yy = 0 TO 511
        PSET (xx, yy), a(xx, yy)
    NEXT
NEXT
CLOSE x
PRINT "That's how you share data folks!" 'G@lleon

Run it once as a host.  Run it a second time to connect as a client and receive data from that host.
Reply




Users browsing this thread: 1 Guest(s)