NetConnect
NetConnect (स्टेटमेंट)
प्रारूप
netconnect सर्वर_नाम, पोर्ट_संख्या
netconnect ( सर्वर_नाम, पोर्ट_संख्या )
netconnect नेटवर्क_सॉकेट_संख्या, सर्वर_नाम, पोर्ट_संख्या
netconnect ( नेटवर्क_सॉकेट_संख्या, सर्वर_नाम, पोर्ट_संख्या )
विवरण
किसी सर्वर से नेटवर्क कनेक्शन (क्लाइंट) खोलता है। सर्वर का IP पता या होस्ट नाम सर्वर_नाम आर्ग्युमेंट में, और ख़ास नेटवर्क पोर्ट संख्या पोर्ट_संख्या आर्ग्युमेंट में दी जाती है। नेटवर्क_सॉकेट_संख्या न दी जाए तो सॉकेट संख्या शून्य (0) इस्तेमाल होती है।
उदाहरण
एक ही कंप्यूटर पर BASIC-256 की दो प्रतियाँ खोलें। “सर्वर” कोड एक में और “क्लाइंट” कोड दूसरी में चिपकाएँ। पहले सर्वर चलाएँ, फिर क्लाइंट। आप देख सकते हैं कि संदेश दो अलग प्रोसेसों के बीच कैसे आते-जाते हैं।
सर्वर कोड
# एक संदेश पाएँ और सफलता वापस भेजें
print "wait for connection on " + netaddress()
netlisten 9997
print "got connection"
do
while not netdata
pause .1
print ".";
end while
n$ = netread
print n$
netwrite "I got '" + n$ + "'."
until n$ = "end"
netclose
यह दिखाएगा (जहाँ xxx.xxx.xxx.xxx आपके कंप्यूटर का IPv4 पता है):
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
क्लाइंट कोड
# उपयोगकर्ता से संदेश लेकर सर्वर को भेजें
input "enter message?", m$
netconnect "127.0.0.1", 9997
for t = 1 to 10
pause rand
netwrite t + " " + m$
print netread
next t
netwrite "end"
print netread
netclose
यह दिखाएगा:
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 'end'.
यह भी देखें
Freenet, NetAddress, NetClose, NetConnect, NetData, NetListen, NetRead, NetWrite
इतिहास
| 0.9.6.31 | इस संस्करण में नया |