This shows you the differences between two versions of the page.
en:netconnect [2016/08/13 08:26] admin |
en:netconnect [2020/02/28 10:46] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== NetConnect (Statement) ===== | ||
- | ==== Format ==== | ||
- | **netconnect** // | ||
- | **netconnect** ( // | ||
- | **netconnect** [[integerexpressions|network_socket_number]], | ||
- | **netconnect** ( [[integerexpressions|network_socket_number]], | ||
- | |||
- | ==== Description ==== | ||
- | Open a network connection (client) to a server. | ||
- | |||
- | ==== Example ==== | ||
- | Open two instances of BASIC-256 on a single computer. | ||
- | |||
- | === Server Code === | ||
- | < | ||
- | # get a message and send back success | ||
- | print "wait for connection on " + netaddress() | ||
- | netlisten 9997 | ||
- | print "got connection" | ||
- | do | ||
- | while not netdata | ||
- | pause .1 | ||
- | print " | ||
- | end while | ||
- | n$ = netread | ||
- | print n$ | ||
- | | ||
- | until n$ = " | ||
- | netclose | ||
- | </ | ||
- | will display (where xxx.xxx.xxx.xxx is the IPv4 address of your computer) | ||
- | < | ||
- | wait for connection on xxx.xxx.xxx.xxx | ||
- | got connection | ||
- | .1 Hi There | ||
- | ....2 Hi There | ||
- | ........3 Hi There | ||
- | ..........4 Hi There | ||
- | .....5 Hi There | ||
- | .......6 Hi There | ||
- | ....7 Hi There | ||
- | ..........8 Hi There | ||
- | ....9 Hi There | ||
- | .....10 Hi There | ||
- | .end | ||
- | </ | ||
- | |||
- | === Client Code === | ||
- | < | ||
- | # have the user enter a message and send it to the server | ||
- | input "enter message?", | ||
- | netconnect " | ||
- | for t = 1 to 10 | ||
- | pause rand | ||
- | | ||
- | print netread | ||
- | next t | ||
- | netwrite " | ||
- | print netread | ||
- | netclose | ||
- | </ | ||
- | will display | ||
- | < | ||
- | enter message?Hi There | ||
- | I got '1 Hi There' | ||
- | I got '2 Hi There' | ||
- | I got '3 Hi There' | ||
- | I got '4 Hi There' | ||
- | I got '5 Hi There' | ||
- | I got '6 Hi There' | ||
- | I got '7 Hi There' | ||
- | I got '8 Hi There' | ||
- | I got '9 Hi There' | ||
- | I got '10 Hi There' | ||
- | I got ' | ||
- | </ | ||
- | |||
- | ==== See Also ==== | ||
- | {{page> | ||
- | |||
- | ==== History ==== | ||
- | |0.9.6.31|New To Version| |