<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Basic_TCP_Client</id>
		<title>Basic TCP Client - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.ethernut.de/nutwiki/index.php?action=history&amp;feed=atom&amp;title=Basic_TCP_Client"/>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Basic_TCP_Client&amp;action=history"/>
		<updated>2026-04-18T19:48:00Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Basic_TCP_Client&amp;diff=22&amp;oldid=prev</id>
		<title>Harald: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Basic_TCP_Client&amp;diff=22&amp;oldid=prev"/>
				<updated>2016-10-27T16:02:52Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 16:02, 27 October 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Harald</name></author>	</entry>

	<entry>
		<id>http://www.ethernut.de/nutwiki/index.php?title=Basic_TCP_Client&amp;diff=21&amp;oldid=prev</id>
		<title>Daniel: /* See also */</title>
		<link rel="alternate" type="text/html" href="http://www.ethernut.de/nutwiki/index.php?title=Basic_TCP_Client&amp;diff=21&amp;oldid=prev"/>
				<updated>2008-12-02T17:44:10Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;See also&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;First register network driver and configure interface by using DHCP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
NutRegisterDevice(&amp;amp;DEV_ETHER, 0, 0);&lt;br /&gt;
if (NutDhcpIfConfig(DEV_ETHER_NAME, 0, 60000)) {&lt;br /&gt;
    /* Error: Cannot configure interface. */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several alternatives:&lt;br /&gt;
* [[Network Configuration Using Hard Coded Configuration]]&lt;br /&gt;
* [[Network Configuration Using Stored Configuration]]&lt;br /&gt;
* [[Network Configuration Using a Configuration Editor]]&lt;br /&gt;
&lt;br /&gt;
Next, connect the server with the given IP address (192.168.1.100) at a specified port (8000).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
sock = NutTcpCreateSocket();&lt;br /&gt;
if (NutTcpConnect(sock, inet_addr(&amp;quot;192.168.1.100&amp;quot;), 8000)) {&lt;br /&gt;
    /* Error: Cannot connect server. */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may then send data to the server...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (NutTcpSend(sock, buffer, len) != len) {&lt;br /&gt;
    /* Error: Cannot send data. */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... or receive data from the server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
got = NutTcpRecv(sock, buffer, len);&lt;br /&gt;
if (got &amp;lt;= 0) {&lt;br /&gt;
    /* Error: Cannot receive data. */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When done, close the connection by closing the socket.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
NutTcpCloseSocket(sock);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more advanced applications you can redirect the connected socket to a file stream and use standard I/O functions like fprintf() or fscanf() for sending and receiving data. The snippet below used fwrite() and fread().&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
FILE *stream;&lt;br /&gt;
/* ... more code here ... */&lt;br /&gt;
&lt;br /&gt;
stream = _fdopen((int) sock, &amp;quot;r+b&amp;quot;);&lt;br /&gt;
/* ... more code here ... */&lt;br /&gt;
&lt;br /&gt;
/* Sending data. */&lt;br /&gt;
fwrite(buffer, 1, len, stream);&lt;br /&gt;
/* ... more code here ... */&lt;br /&gt;
&lt;br /&gt;
/* Receiving data. */&lt;br /&gt;
got = fread(buffer, 1, len, stream);&lt;br /&gt;
/* ... more code here ... */&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Do not forget to close the stream with fclose() and socket with NutTcpCloseSocket().&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Basic TCP Server]]&lt;br /&gt;
* [[Network Configuration Using Stored Configuration]]&lt;br /&gt;
* [[Network Configuration Using Hard Coded Configuration]]&lt;br /&gt;
* [[Network Configuration Using a Configuration Editor]]&lt;br /&gt;
* [[Discovery Service]]&lt;br /&gt;
* More [[Nut/OS Examples]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Snippets]]&lt;br /&gt;
&lt;br /&gt;
{{Languages}}&lt;/div&gt;</summary>
		<author><name>Daniel</name></author>	</entry>

	</feed>