<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ro">
	<id>http://wiki.dcae.pub.ro/index.php?action=history&amp;feed=atom&amp;title=Network_Sockets</id>
	<title>Network Sockets - Revizia istoricului</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.dcae.pub.ro/index.php?action=history&amp;feed=atom&amp;title=Network_Sockets"/>
	<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;action=history"/>
	<updated>2026-05-27T08:07:53Z</updated>
	<subtitle>Istoricul versiunilor pentru această pagină din wiki</subtitle>
	<generator>MediaWiki 1.35.14</generator>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1610&amp;oldid=prev</id>
		<title>Rhobincu: /* Server Socket */</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1610&amp;oldid=prev"/>
		<updated>2013-12-23T12:03:21Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Server Socket&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 23 decembrie 2013 12:03&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l75&quot; &gt;Linia 75:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 75:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Attention:&amp;lt;/font&amp;gt; Method &amp;#039;&amp;#039;ServerSocket.accept()&amp;#039;&amp;#039; is blocking! That means that once the method called, the program is blocked until a client initiates a connection. Only in that moment will the &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039; method return an object of type &amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039; associated with that client. At the same time, a client can not connect as long as the server isn&amp;#039;t blocked in the method &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Attention:&amp;lt;/font&amp;gt; Method &amp;#039;&amp;#039;ServerSocket.accept()&amp;#039;&amp;#039; is blocking! That means that once the method called, the program is blocked until a client initiates a connection. Only in that moment will the &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039; method return an object of type &amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039; associated with that client. At the same time, a client can not connect as long as the server isn&amp;#039;t blocked in the method &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1609&amp;oldid=prev</id>
		<title>Rhobincu: /* Socket de server */</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1609&amp;oldid=prev"/>
		<updated>2013-12-23T12:03:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Socket de server&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 23 decembrie 2013 12:03&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l70&quot; &gt;Linia 70:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 70:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Socket &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;de server &lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Server &lt;/ins&gt;Socket ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Rolul unui &lt;/del&gt;socket &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;de server este de a accepta conexiuni pe la unul sau mai multi clienți&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Clasa care implementează acest comportament este &lt;/del&gt;[http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html java.net.ServerSocket]. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Pentru ca un &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;ServerSocket&amp;#039;&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;să poată funcționa, are nevoie de o singură informație, și anume portul pe care să accepte conexiuni. Pentru a efectua o conectare concretă&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;clasa conține o metodă numită &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The role of a server &lt;/ins&gt;socket &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is to accept connections from one or more clients&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The class that implements this behavior is &lt;/ins&gt;[http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html java.net.ServerSocket]. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;For a &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;ServerSocket&amp;#039;&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;to function&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;it needs only one information&lt;/ins&gt;: &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the port on which to listen to&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;To actually &lt;/ins&gt;accept &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;connections&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the class contains a method called &lt;/ins&gt;&amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Atenție&lt;/del&gt;:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/font&amp;gt; Metoda &amp;#039;&amp;#039;ServerSocket&lt;/del&gt;.accept&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;()&amp;#039;&amp;#039; este blocantă! Asta implică faptul că odată intrat în metodă&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;programul se blochează până în momentul în care un client încearcă să se conecteze. În acel moment abia, metoda &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039; întoarce un obiect de tip &amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039; asociat acelei conexiuni. În același timp, un client nu se poate conecta atâta timp cât serverul nu este blocat în metoda &lt;/del&gt;&amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/div&amp;gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Attention:&amp;lt;/font&amp;gt; Method &amp;#039;&amp;#039;ServerSocket.accept()&amp;#039;&amp;#039; is blocking! That means that once the method called, the program is blocked until a client initiates a connection. Only in that moment will the &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039; method return an object of type &amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039; associated with that client. At the same time, a client can not connect as long as the server isn&amp;#039;t blocked in the method &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&amp;lt;/div&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l125&quot; &gt;Linia 125:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 124:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Puteți verifica funcționarea acestui &lt;/del&gt;server &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;modificând clientul pentru a se conecta la &lt;/del&gt;&amp;quot;localhost&amp;quot;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;pe portul &lt;/del&gt;9000 &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;și rulând ambele programe pe același calculator&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;în console diferite&lt;/del&gt;.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;You can check if this &lt;/ins&gt;server &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is working by modifying the client above to connect to &lt;/ins&gt;&amp;quot;localhost&amp;quot;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;on port &lt;/ins&gt;9000 &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;and running both programs on the same computer&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;in different consoles&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Pentru &lt;/del&gt;a &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;putea programa un server care să administreze mai mulți clienți simultan&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;trebuie obligatoriu create mai multe fire de execuție (thread&lt;/del&gt;-&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;uri)&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;In order to program &lt;/ins&gt;a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;service to administer multiple client at the same time&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;it must be implemented using multiple execution threads, or otherwise said, by using [[Concurrent Programming &lt;/ins&gt;- &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Threads|multithreading]]&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1608&amp;oldid=prev</id>
		<title>Rhobincu: /* Client Sockets */</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1608&amp;oldid=prev"/>
		<updated>2013-12-23T11:56:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Client Sockets&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ro&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Versiunea anterioară&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Versiunea de la data 23 decembrie 2013 11:56&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l37&quot; &gt;Linia 37:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Linia 37:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Client Sockets ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Client Sockets ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;În general&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;o conexiunea de rețea se realizează dinspre o stație (&lt;/del&gt;host&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;) numită &lt;/del&gt;&amp;#039;&amp;#039;client&amp;#039;&amp;#039;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;, către o altă stație, numită &lt;/del&gt;&amp;#039;&amp;#039;server&amp;#039;&amp;#039;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Pentru ca un &lt;/del&gt;client &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;să se poată conecta la un &lt;/del&gt;server, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;are nevoie de două informații&lt;/del&gt;: &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;adresa serverului și portul pe care ascultă aplicația la care se dorește conectarea&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Clasa care realizează acest lucru în &lt;/del&gt;Java &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;se numește &lt;/del&gt;[http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html java.net.Socket]. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Orice obiect de tip &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;după instanțiere&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;are asociate două &amp;#039;&amp;#039;stream&amp;#039;&amp;#039;-uri&lt;/del&gt;:  &lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Generally&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;a network connection is established from a &lt;/ins&gt;host &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;called &lt;/ins&gt;&amp;#039;&amp;#039;client&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;to another host called &lt;/ins&gt;&amp;#039;&amp;#039;server&amp;#039;&amp;#039;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;For a &lt;/ins&gt;client &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;to connect to a &lt;/ins&gt;server, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;it needs two pieces of information&lt;/ins&gt;: &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the address of the server and the port on which the service application listens to&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The class which implements the client functionality in &lt;/ins&gt;Java &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is called &lt;/ins&gt;[http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html java.net.Socket]. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Any object of type &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;after instantiation&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;has two associated streams&lt;/ins&gt;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;un &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;InputStream&amp;#039;&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;de pe care se pot citi date venite de la celălalt capăt al conexiunii&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;accesibil cu metoda &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;Socket.getInputStream()&amp;#039;&amp;#039;&amp;#039;;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;InputStream&amp;#039;&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;from which you can read data coming from the other side of the connection&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;accessible by method &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;Socket.getInputStream()&amp;#039;&amp;#039;&amp;#039;;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;un &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;OutputStream&amp;#039;&amp;#039;&amp;#039; &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;pe care se pot scrie date pentru a fi trimise la celălalt capăt al conexiunii&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;accesibil cu metoda &lt;/del&gt;&amp;#039;&amp;#039;&amp;#039;Socket.getOutputStream()&amp;#039;&amp;#039;&amp;#039;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;OutputStream&amp;#039;&amp;#039;&amp;#039; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;on which you can write data to the other side of the connection&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;accessible by method &lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039;Socket.getOutputStream()&amp;#039;&amp;#039;&amp;#039;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;; &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
	<entry>
		<id>http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1607&amp;oldid=prev</id>
		<title>Rhobincu: Pagină nouă: The Java language, through the API library, provides native support for network communication. The easiest way to communicate between two machines is by using [http://en.wikipedia.org...</title>
		<link rel="alternate" type="text/html" href="http://wiki.dcae.pub.ro/index.php?title=Network_Sockets&amp;diff=1607&amp;oldid=prev"/>
		<updated>2013-12-23T11:51:11Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: The Java language, through the API library, provides native support for network communication. The easiest way to communicate between two machines is by using [http://en.wikipedia.org...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pagină nouă&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The Java language, through the API library, provides native support for network communication. The easiest way to communicate between two machines is by using [http://en.wikipedia.org/wiki/Network_socket netowrk sockets]. Sockets are network communication mechanisms (developed at The Berkeley University of California) which can use any communication protocol, although usually they&amp;#039;re using the ones defined in the TCP/IP stack.&lt;br /&gt;
&lt;br /&gt;
Any computer connected to the Internet needs to have a address by which it is identified, called an IP (internet protocol) address. A IPv4 address (version 4) is made up of 4 bytes and the external representation is done by writing the four bytes separated by dots (E.g.: 192.168.0.1). Besides an IP address, a computer can also have symbolic names, grouped in domains (E.g.: dcae.pub.ro), and the correspondence between IP addresses and symbolic names are stored in a distributed database, accessed through the domain name service (DNS).&lt;br /&gt;
&lt;br /&gt;
In Java, classes and interfaces related to network programming are stored in package [http://docs.oracle.com/javase/7/docs/api/java/net/package-summary.html java.net]. An IP address is represented through class [http://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html InetAddress], which contains both the IP address (in numerical format) as well as the symbolic corresponding name. This class does not have a public constructor, so an object of this type can be created by calling some of the class&amp;#039;s static methods: &amp;#039;&amp;#039;getByName()&amp;#039;&amp;#039;, &amp;#039;&amp;#039;getLocalHost()&amp;#039;&amp;#039; or &amp;#039;&amp;#039;getAllByName()&amp;#039;&amp;#039; which return the reference to the newly created object. For example, the prototype for method &amp;#039;&amp;#039;getByName()&amp;#039;&amp;#039; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public InetAddress getByName (String host) throws UnknownHostException;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The argument of the method (host), is a String representing the name of the machine as a symbolic name (E.g.: www.upb.ro) or as a textual representation of the IP address (&amp;quot;141.85.94.1&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
Sockets can be used in one of the two possible ways:&lt;br /&gt;
* unconnected sockets (UDP protocol);&lt;br /&gt;
* connected sockets (TCP protocol).&lt;br /&gt;
&lt;br /&gt;
Unconnected sockets send packets using the UDP protocol ([http://en.wikipedia.org/wiki/User_Datagram_Protocol User Datagram Protocol]) between processes which don&amp;#039;t have a permanent link. &lt;br /&gt;
&lt;br /&gt;
Connected sockets first establish a connection between sockets belonging to different processes. Connected sockets use the TCP protocol ([http://en.wikipedia.org/wiki/Transmission_Control_Protocol Transmission Control Protocol]) which is a reliable protocol (with error checking and re-transmission), unlike UDP which is not reliable. &lt;br /&gt;
&lt;br /&gt;
In order for multiple applications to access the network at the same time, packages for each application need to be separate. This is achieved by using [http://en.wikipedia.org/wiki/Port_number communication ports]. A port is a 16-bit number and every application uses a unique one to communicate. A connection has two ports, one on each side of connection. The client port is allocated by the operating system, when the connection is initiated, and the server port is constant and depends on the service provided. Each standard protocol has an associated port number according to the list maintained by [http://en.wikipedia.org/wiki/Internet_Assigned_Numbers_Authority Internet Assigned Numbers Authority]. Examples are:&lt;br /&gt;
&lt;br /&gt;
* port 20 - File Transfer Protocol (data)&lt;br /&gt;
* port 21 - File Transfer Protocol (control)&lt;br /&gt;
* port 21 - Secure Shell (SSH)&lt;br /&gt;
* port 25 - Simple Mail Transfer Protocol (SMTP)&lt;br /&gt;
* port 80 - Hyper Text Transfer Protocol (HTTP)&lt;br /&gt;
* etc.&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers Here] you have the complete list.&lt;br /&gt;
&lt;br /&gt;
In a Linux operating system, ports from 0 to 1023 are reserved by the kernel and are not accessible unless you have root privileges. In Linux, to find out what ports are opened (used), you can use the &amp;#039;&amp;#039;nmap&amp;#039;&amp;#039; command, if it&amp;#039;s installed:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nmap arh.pub.ro&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Client Sockets ==&lt;br /&gt;
&lt;br /&gt;
În general, o conexiunea de rețea se realizează dinspre o stație (host) numită &amp;#039;&amp;#039;client&amp;#039;&amp;#039;, către o altă stație, numită &amp;#039;&amp;#039;server&amp;#039;&amp;#039;. Pentru ca un client să se poată conecta la un server, are nevoie de două informații: adresa serverului și portul pe care ascultă aplicația la care se dorește conectarea. Clasa care realizează acest lucru în Java se numește [http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html java.net.Socket]. Orice obiect de tip &amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039;, după instanțiere, are asociate două &amp;#039;&amp;#039;stream&amp;#039;&amp;#039;-uri: &lt;br /&gt;
* un &amp;#039;&amp;#039;&amp;#039;InputStream&amp;#039;&amp;#039;&amp;#039; de pe care se pot citi date venite de la celălalt capăt al conexiunii, accesibil cu metoda &amp;#039;&amp;#039;&amp;#039;Socket.getInputStream()&amp;#039;&amp;#039;&amp;#039;;&lt;br /&gt;
* un &amp;#039;&amp;#039;&amp;#039;OutputStream&amp;#039;&amp;#039;&amp;#039; pe care se pot scrie date pentru a fi trimise la celălalt capăt al conexiunii, accesibil cu metoda &amp;#039;&amp;#039;&amp;#039;Socket.getOutputStream()&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.net.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Client{&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] _args){&lt;br /&gt;
    try{&lt;br /&gt;
        //connect to arh.pub.ro on the HTTP port&lt;br /&gt;
        Socket _clientSocket = new Socket(&amp;quot;arh.pub.ro&amp;quot;, 80);&lt;br /&gt;
        OutputStream _outputStream = _clientSocket.getOutputStream();&lt;br /&gt;
        InputStream _inputStream = _clientSocket.getInputStream();&lt;br /&gt;
&lt;br /&gt;
        _outputStream.write(&amp;quot;GET /java.txt\n&amp;quot;.getBytes());&lt;br /&gt;
&lt;br /&gt;
        int _char;&lt;br /&gt;
        while((_char = _inputStream.read()) != -1){&lt;br /&gt;
            System.out.print((char)_char);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        _clientSocket.close();&lt;br /&gt;
    }catch(IOException _ioe){&lt;br /&gt;
        System.out.println(&amp;quot;Communication problem: &amp;quot; + _ioe.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Socket de server ==&lt;br /&gt;
&lt;br /&gt;
Rolul unui socket de server este de a accepta conexiuni pe la unul sau mai multi clienți. Clasa care implementează acest comportament este [http://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html java.net.ServerSocket]. Pentru ca un &amp;#039;&amp;#039;&amp;#039;ServerSocket&amp;#039;&amp;#039;&amp;#039; să poată funcționa, are nevoie de o singură informație, și anume portul pe care să accepte conexiuni. Pentru a efectua o conectare concretă, clasa conține o metodă numită &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;regula&amp;quot;&amp;gt;&amp;lt;font color=&amp;quot;#ff0000&amp;quot;&amp;gt;Atenție:&amp;lt;/font&amp;gt; Metoda &amp;#039;&amp;#039;ServerSocket.accept()&amp;#039;&amp;#039; este blocantă! Asta implică faptul că odată intrat în metodă, programul se blochează până în momentul în care un client încearcă să se conecteze. În acel moment abia, metoda &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039; întoarce un obiect de tip &amp;#039;&amp;#039;&amp;#039;Socket&amp;#039;&amp;#039;&amp;#039; asociat acelei conexiuni. În același timp, un client nu se poate conecta atâta timp cât serverul nu este blocat în metoda &amp;#039;&amp;#039;accept()&amp;#039;&amp;#039;.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.net.*;&lt;br /&gt;
import java.io.*;&lt;br /&gt;
&lt;br /&gt;
public class Server{&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] _args){&lt;br /&gt;
    try{&lt;br /&gt;
        // start a new server on port 9000 (must be higher or equal to 1024)&lt;br /&gt;
        ServerSocket _serverSocket = new ServerSocket(9000);&lt;br /&gt;
&lt;br /&gt;
        // listen to an incoming connection and creating a communication socket&lt;br /&gt;
        // accept() is blocking&lt;br /&gt;
        System.out.print(&amp;quot;Listening for inc. connections... &amp;quot;);&lt;br /&gt;
        Socket _socket = _serverSocket.accept();&lt;br /&gt;
        System.out.println(&amp;quot;connected!&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        // get the streams associated with the socket&lt;br /&gt;
        // output one always first&lt;br /&gt;
        OutputStream _outputStream = _socket.getOutputStream();&lt;br /&gt;
        InputStream _inputStream = _socket.getInputStream();&lt;br /&gt;
&lt;br /&gt;
        // read the input char by char until newline char (\n)&lt;br /&gt;
        // we could do the same thing easier using an InputStreamReader&lt;br /&gt;
        // and a BufferedReader&lt;br /&gt;
        String _command = &amp;quot;&amp;quot;;&lt;br /&gt;
        char _char;&lt;br /&gt;
        while((_char = (char)_inputStream.read()) != &amp;#039;\n&amp;#039;){&lt;br /&gt;
            _command = _command + _char;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        // send a response depending on the received string &lt;br /&gt;
        if(_command.equals(&amp;quot;GET /java.txt&amp;quot;)){&lt;br /&gt;
            _outputStream.write(&amp;quot;Congratulations, you have received a message from a Java server!\n&amp;quot;.getBytes());&lt;br /&gt;
        }else{&lt;br /&gt;
            _outputStream.write(&amp;quot;Congratulations, you still received a message from a Java server, even though you sent the wrong text!\n&amp;quot;.getBytes());&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        _socket.close();&lt;br /&gt;
        _serverSocket.close();&lt;br /&gt;
    }catch(IOException _ioe){&lt;br /&gt;
        System.out.println(&amp;quot;Communication problem: &amp;quot; + _ioe.getMessage());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Puteți verifica funcționarea acestui server modificând clientul pentru a se conecta la &amp;quot;localhost&amp;quot;, pe portul 9000 și rulând ambele programe pe același calculator, în console diferite. &lt;br /&gt;
&lt;br /&gt;
Pentru a putea programa un server care să administreze mai mulți clienți simultan, trebuie obligatoriu create mai multe fire de execuție (thread-uri).&lt;/div&gt;</summary>
		<author><name>Rhobincu</name></author>
	</entry>
</feed>