1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
<!DOCTYPE html>
<html lang="en" dir="ltr" class="no-js">
<head>
<meta charset="utf-8" />
<title>pt:netconnect [BASIC 256 - Language Documentation]</title>
<link rel="stylesheet" type="text/css" href="lib/exe/cssc171c1dfe8519125bb40a349172b001a.css"/>
</head>
<body>
<div id="dokuwiki__site"><div id="dokuwiki__top" class="site dokuwiki mode_show tpl_dokuwiki ">
<div id="dokuwiki__header"><div class="pad group">
<div class="headings group">
<h1><a href="start.html" accesskey="h" title="[H]"><img src="lib/tpl/dokuwiki/images/logo.png" width="64" height="64" alt="" /> <span>BASIC 256 - Language Documentation</span></a></h1>
</div>
</div>
<div class="breadcrumbs">
<div class="youarehere"><span class="bchead">You are here: </span><span class="home"><bdi><a href="start.html" class="wikilink1" title="start">start</a></bdi></span> » <bdi><a href="pt_start.html" class="wikilink1" title="pt:start">pt</a></bdi> » <bdi><span class="curid"><a href="pt_netconnect.html" class="wikilink1" title="pt:netconnect">netconnect</a></span></bdi></div>
</div>
<hr class="a11y" />
</div></div>
<div class="wrapper group">
<div id="dokuwiki__content"><div class="pad group">
<div class="pageId"><span>pt:netconnect</span></div>
<div class="page group">
<div id="dw__toc">
<h3 class="toggle">Table of Contents</h3>
<div>
<ul class="toc">
<li class="level2"><div class="li"><a href="pt_netconnect.html#netconnect">NetConnect</a></div>
<ul class="toc">
<li class="level3"><div class="li"><a href="pt_netconnect.html#formato">Formato</a></div></li>
<li class="level3"><div class="li"><a href="pt_netconnect.html#descricao">Descrição</a></div></li>
<li class="level3"><div class="li"><a href="pt_netconnect.html#exemplo">Exemplo</a></div></li>
<li class="level3"><div class="li"><a href="pt_netconnect.html#ver_tambem">Ver também</a></div></li>
<li class="level3"><div class="li"><a href="pt_netconnect.html#desde">Desde</a></div></li>
</ul></li>
</ul>
</div>
</div>
<h2 class="sectionedit1" id="netconnect">NetConnect</h2>
<div class="level2">
</div>
<h3 class="sectionedit2" id="formato">Formato</h3>
<div class="level3">
<p>
<strong>netconnect</strong> <em>server_name</em>, <em>port_number</em><br/>
<strong>netconnect</strong> ( <em>server_name</em>, <em>port_number</em> )<br/>
<strong>netconnect</strong> <em><a class="explain" href="pt_netconnect.html">socket_number</a></em>, <em>server_name</em>, <em>port_number</em><br/>
<strong>netconnect</strong> ( <em><a class="explain" href="pt_netconnect.html">socket_number</a></em>, <em>server_name</em>, <em>port_number</em> )
</p>
</div>
<h3 class="sectionedit3" id="descricao">Descrição</h3>
<div class="level3">
<p>
Abre uma ligação em rede (client) com um servidor. O endereço IP ou nome do servidor são especificados em <em>server_name</em> argument, e o número da entrada (port) em <em>port_number</em>. Se o número da ligação <em><a class="explain" href="pt_netconnect.html">socket_number</a></em> não for especificado então o (0) será usado.
</p>
</div>
<h3 class="sectionedit4" id="exemplo">Exemplo</h3>
<div class="level3">
<p>
Abra duas instâncias de Basic 256 no mesmo computador. Copie o código “servidor” para um e o código “cliente” para outro. Corra primeiro o servidor e depois o cliente. Note como as duas instancias do programa comunicam.
</p>
</div>
<h4 id="servidor">Servidor</h4>
<div class="level4">
<pre class="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$
netwrite "I got '" + n$ + "'."
until n$ = "end"
netclose</pre>
<p>
will display (where xxx.xxx.xxx.xxx is the IPv4 address of your computer)
</p>
<pre class="code">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</pre>
</div>
<h4 id="cliente">Cliente</h4>
<div class="level4">
<pre class="code"># have the user enter a message and send it to the server
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</pre>
<p>
will display
</p>
<pre class="code">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'.</pre>
</div>
<h3 class="sectionedit5" id="ver_tambem">Ver também</h3>
<div class="level3">
<p>
<a href="pt_netaddress.html" class="wikilink1" title="pt:netaddress">NetAddress</a>, <a href="pt_netclose.html" class="wikilink1" title="pt:netclose">NetClose</a>, <a href="pt_netdata.html" class="wikilink1" title="pt:netdata">NetData</a>, <a href="pt_netlisten.html" class="wikilink1" title="pt:netlisten">NetListen</a>, <a href="pt_netread.html" class="wikilink1" title="pt:netread">NetRead</a>, <a href="pt_netwrite.html" class="wikilink1" title="pt:netwrite">NetWrite</a>
</p>
</div>
<h3 class="sectionedit6" id="desde">Desde</h3>
<div class="level3">
<p>
0.9.6.31
</p>
</div>
</div>
<div class="docInfo"><bdi>pt/netconnect.txt</bdi> · Last modified: 2012/12/19 07:18 by <bdi>m_santos</bdi></div>
</div></div>
<hr class="a11y" />
</div>
<div id="dokuwiki__footer"><div class="pad">
<div class="license">Except where otherwise noted, content on this wiki is licensed under the following license: <bdi><a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license" class="urlextern">CC Attribution-Share Alike 3.0 Unported</a></bdi></div>
</div></div>
</div></div>
<div id="screen__mode" class="no"></div>
</body>
</html>
|