<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Florent Clairambault &#187; network</title>
	<atom:link href="http://florent.clairambault.fr/tag/network/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>TC65 HTTP POST request</title>
		<link>http://florent.clairambault.fr/tc65-http-post-request?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tc65-http-post-request</link>
		<comments>http://florent.clairambault.fr/tc65-http-post-request#comments</comments>
		<pubDate>Sun, 25 Oct 2009 21:45:43 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[TC65]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1865</guid>
		<description><![CDATA[This is just a quick code to show how to do a simple http POST request from a TC65 chip. 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 [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick code to show how to do a simple http POST request from a TC65 chip.</p>

<div class="wp_codebox"><table><tr id="p18652"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p1865code2"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> httpCheck<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> data <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Parameter1=000009960623185&amp;Parameter2=$GPWPL,4807.038,N,01131.000,E,WPTNME*5C&quot;</span><span style="color: #339933;">;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> url <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://test.webingenia.com/postIdent&quot;</span><span style="color: #339933;">;</span>
        HttpConnection conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a> is <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aoutputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">OutputStream</span></a> os <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Test HTTP connection</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// We prepare the POST request</span>
            conn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HttpConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span> url <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            conn.<span style="color: #006633;">setRequestMethod</span><span style="color: #009900;">&#40;</span> HttpConnection.<span style="color: #006633;">POST</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Content-Type&quot;</span>, <span style="color: #0000ff;">&quot;application/x-www-form-urlencoded&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            os <span style="color: #339933;">=</span> conn.<span style="color: #006633;">openOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            os.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span> data.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// We launch the request</span>
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Response code : &quot;</span> <span style="color: #339933;">+</span> conn.<span style="color: #006633;">getResponseCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// We display the generated content</span>
            is <span style="color: #339933;">=</span> conn.<span style="color: #006633;">openInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">int</span> ch<span style="color: #339933;">;</span>
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Output : &quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>ch <span style="color: #339933;">=</span> is.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span>
                <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#41;</span> ch <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Http : ex : &quot;</span> <span style="color: #339933;">+</span> ex.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; : &quot;</span> <span style="color: #339933;">+</span> ex.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// Whatever happens, we close everything</span>
        <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> conn <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
                    conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> is <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
                    is.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> os <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
                    os.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Http : ex2 : &quot;</span> <span style="color: #339933;">+</span> ex.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; : &quot;</span> <span style="color: #339933;">+</span> ex.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                ex.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/tc65-http-post-request/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Server-Side HTTP Request tester</title>
		<link>http://florent.clairambault.fr/server-side-http-request-tester?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=server-side-http-request-tester</link>
		<comments>http://florent.clairambault.fr/server-side-http-request-tester#comments</comments>
		<pubDate>Sun, 25 Oct 2009 08:30:43 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[TC65]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1860</guid>
		<description><![CDATA[I made this simple test website for those of you who would want to check if their HTTP request made from a simple equipment like the TC65 are sent correctly. The idea is simple : You choose an id like &#8220;ThisIsMe&#8221; You access the test website with this id : http://test.webingenia.com/ThisIsMe You check what was [...]]]></description>
			<content:encoded><![CDATA[<p>I made this simple test website for those of you who would want to check if their HTTP request made from a simple equipment like the <a href="http://florent.clairambault.fr/tag/tc65">TC65</a> are sent correctly.</p>
<p>The idea is simple : </p>
<ul>
<li>You choose an id like &#8220;ThisIsMe&#8221;</li>
<li>You access the test website with this id : <a href="http://test.webingenia.com/ThisIsMe">http://test.webingenia.com/ThisIsMe</a></li>
<li>You check what was the content of the request at this address : <a href="http://test.webingenia.com/read/ThisIsMe">http://test.webingenia.com/read/ThisIsMe</a></a></li>
</ul>
<p>You can contact me if you don&#8217;t understand something, if something doesn&#8217;t work or if you would like me to add a feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/server-side-http-request-tester/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TC65 : Slow UDP reception</title>
		<link>http://florent.clairambault.fr/tc65-slow-udp-reception?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tc65-slow-udp-reception</link>
		<comments>http://florent.clairambault.fr/tc65-slow-udp-reception#comments</comments>
		<pubDate>Sun, 10 May 2009 11:08:48 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[J2ME]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[TC65]]></category>
		<category><![CDATA[UDP]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=731</guid>
		<description><![CDATA[Receiving UDP datagrams on the TC65 is easy but inefficient. You need to create a new thread if you want to receive data asynchronously. There&#8217;s no way of knowing if a new datagram has been received or not without hanging on the ::receive( Datagram ); method. This is quite weird considering you can do it [...]]]></description>
			<content:encoded><![CDATA[<p>Receiving UDP datagrams on the TC65 is easy but inefficient. You need to create a new thread if you want to receive data asynchronously. There&#8217;s no way of knowing if a new datagram has been received or not without hanging on the ::receive( Datagram ); method. This is quite weird considering you can do it in TCP.</p>
<p>The real problem is it&#8217;s freaking slow. The Cinterion documentation just tells you &#8220;This method blocks until a datagram is received.&#8221;. What it doesn&#8217;t say is that nearly each time, it blocks for 100 to 700 ms after UDP datagrams have actually been received. And worse, this slowness/sleeping avoids the program from treating data and finally throws a little java.io.IOException exception :  &#8220;No buffer space available&#8221;. I tried to give the udp receiving thread a higher priority than the other threads, I tried to make the TCP reception thread sleep a lot just in case it would lock some kind of network object, I looked on <a href="http://jcs.mobile-utopia.com/jcs/20027_Protocol.java">how could this method be implemented</a> but couldn&#8217;t find a solution and don&#8217;t believe there&#8217;s one.</p>
<p>By the way, most of the codes on UDP data reception are lame. They all show the same stupid synchronous code. The real code you will need is something like that :</p>
<p><i>You can remove the Logger class calls. It enables me to make some build-specific (mostly logging) code. The &#8220;if&#8221; false conditions are remove by the java compiler (which is actually mostly a pre-compiler). I will (quickly this time) talk about this someday&#8230;</i></p>
<p><i>This program isn&#8217;t TC65 specific, it should work with any <a href="http://en.wikipedia.org/wiki/Mobile_Information_Device_Profile#javax.microedition.io">MIDP enabled J2ME device</a></i>.</p>

<div class="wp_codebox"><table><tr id="p7316"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p731code6"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">Network.UDPReceiver</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">Common.Logger</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.io.Datagram</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.microedition.io.DatagramConnection</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * UDP event-like receiving class
 * @author Florent Clairambault
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UDPReceiver <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arunnable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Runnable</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> IUDPReceive _receivingClass<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> DatagramConnection _udpConn<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Datagram _udpDatagram<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> _thread<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> _loop<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Creates and launchs the receiver
     * @param conn The connection
     * @param receivingClass The receiving class of the UDP receive event
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> UDPReceiver<span style="color: #009900;">&#40;</span>DatagramConnection conn, IUDPReceive receivingClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        _udpConn <span style="color: #339933;">=</span> conn<span style="color: #339933;">;</span>
        _receivingClass <span style="color: #339933;">=</span> receivingClass<span style="color: #339933;">;</span>
        init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Prepares the datagram used to receive data
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_VERBOSE</span><span style="color: #009900;">&#41;</span>
            Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">32</span>, <span style="color: #0000ff;">&quot;UDPReceiver.init();&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> maxLength <span style="color: #339933;">=</span> _udpConn.<span style="color: #006633;">getMaximumLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_DEBUG</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">39</span>, <span style="color: #0000ff;">&quot;maxLength=&quot;</span> <span style="color: #339933;">+</span> maxLength <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            _udpDatagram <span style="color: #339933;">=</span> _udpConn.<span style="color: #006633;">newDatagram</span><span style="color: #009900;">&#40;</span> maxLength <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// This should NEVER happen !</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_CRITICAL</span><span style="color: #009900;">&#41;</span>
                Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">37</span>, <span style="color: #0000ff;">&quot;UDPReceiver.init&quot;</span>, ex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * The actual data reception
     * @return the data received
     * @throws java.io.IOException When something fais, it means we have to stop
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> receiveUdpFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_DEBUG</span><span style="color: #009900;">&#41;</span>
            Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">46</span>, <span style="color: #0000ff;">&quot;UDPReceiver.receiveUdpFrame();&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        _udpConn.<span style="color: #006633;">receive</span><span style="color: #009900;">&#40;</span> _udpDatagram <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> _udpDatagram.<span style="color: #006633;">getLength</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_DEBUG</span><span style="color: #009900;">&#41;</span>
            Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">49</span>, <span style="color: #0000ff;">&quot;size = &quot;</span> <span style="color: #339933;">+</span> size <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// We copy the data so that it can be used on an other thread</span>
        <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> data <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span>size<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">arraycopy</span><span style="color: #009900;">&#40;</span> _udpDatagram.<span style="color: #006633;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span>, data, <span style="color: #cc66cc;">0</span>, size <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// These two lines might seem weird but are the more efficient way</span>
        <span style="color: #666666; font-style: italic;">// to prepare next datagram reception.</span>
        _udpDatagram.<span style="color: #006633;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        _udpDatagram.<span style="color: #006633;">setLength</span><span style="color: #009900;">&#40;</span> _udpDatagram.<span style="color: #006633;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_DEBUG</span><span style="color: #009900;">&#41;</span>
            Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">63</span>, <span style="color: #0000ff;">&quot;UDPReceiver.receiveUdpFrame : ok !&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> data<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Starts the receiving thread
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        _loop <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
        _thread <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;udp&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        _thread.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Plan to stop
     * 
     * This method is in fact useless. The thread will stop when the
     * DatagramConnection (_udpConn) will be closed.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> stop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        _loop <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * The thread method
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>_loop<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_DEBUG</span><span style="color: #009900;">&#41;</span>
                    Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">70</span>, <span style="color: #0000ff;">&quot;UDPReceiver : running...&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> data <span style="color: #339933;">=</span> receiveUdpFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// We &quot;throw&quot; an event-like method</span>
                _receivingClass.<span style="color: #006633;">UdpDataReceived</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_DEBUG</span><span style="color: #009900;">&#41;</span>
                Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">54</span>, <span style="color: #0000ff;">&quot;UDPReceiver.run&quot;</span>, ex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// The connection must have been closed, we have to stop !</span>
            _loop <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Logger.<span style="color: #006633;">E_CRITICAL</span><span style="color: #009900;">&#41;</span>
                Logger.<span style="color: #006633;">Log</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">119</span>, <span style="color: #0000ff;">&quot;UDPReceiver.run&quot;</span>, ex <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The &#8220;mother&#8221; class has implements this IUDPReceiver interface :</p>

<div class="wp_codebox"><table><tr id="p7317"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p731code7"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">Network.UDPReceiver</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Interface an asynchronous UDP receiving class must implement
 * @author Florent Clairambault
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> IUDPReceive <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Called when a datagram is received on a connection
     * @param data Content of the datagram
     * 
     * We assume that the receiving class already knows the sender of the
     * datagram because it's a connection established with an &quot;UDP server&quot;.
     */</span>
    <span style="color: #000066; font-weight: bold;">void</span> UdpDataReceived<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> data <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The &#8220;mother&#8221; class should open the connection like that :</p>

<div class="wp_codebox"><table><tr id="p7318"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p731code8"><pre class="java" style="font-family:monospace;">_udpConn <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>UDPDatagramConnection<span style="color: #009900;">&#41;</span> Connector.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;datagram://&quot;</span> <span style="color: #339933;">+</span> server <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
_udpReceiver <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UDPReceiver<span style="color: #009900;">&#40;</span> _udpConn, <span style="color: #000000; font-weight: bold;">this</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>where server is an adresse like that &#8220;x.x.x.x:y&#8221;. It can also be used as a UDP server with &#8220;:y&#8221;.</p>
<p>And has to implement the interface IUDPReceiver interface.</p>
<p><a name="note"></a></p>
<h3>Note on receiving UDP over GPRS</h3>
<p>Most GPRS connections (every one of them unless you subscribe to special options), are &#8220;NATed&#8221; (using a <a href="http://en.wikipedia.org/wiki/Network_address_translation">NAT</a> router). They are behind a private network (10.x.x.x/8, 192.168.x.x/16, 172.16.x.x/12). That prevents the equipments from being directly accessible (by other means than their phone number).</p>
<p>On TCP, you have to establish a connection with a remote host (that you&#8217;re quite likely to call a &#8220;server&#8221;), and then the server can answer on the link. You have a reliable bi-directional stream you can use to transmit anything you&#8217;d like. You can keep the connection open running forever, you just have to send data or set the KeepAlive option. NAT routers break TCP connections when nothing has been transmitted on it for 1 hour to 4 days. This has even been considered like a &#8220;bug&#8221; by some people because the NAT router reach its memory limit or the max number of TCP connections it can translate (from private to public).<br />
On the TC65, it means you can communicate over a TCP connections for months. You just have to make sure that it&#8217;s still alive by providing a little ping mechanism in your protocol (you can send pings every 15/30 minutes for instance).</p>
<p>On UDP, it&#8217;s roughly the same thing except there&#8217;s no connection. In fact, UDP is minimalist (it only has a 8 bytes header). You have no mechanism for connection establishment, you just throw your data (and by chance, it will be received). The router can&#8217;t possibly know when the transmission has ended. So when the router supports bi-directional UDP, it just tries to keep track of the last connections established for a limited time. My personal <a href="http://florent.clairambault.fr/the-tomato-firmware">tomato firmware enabled router</a>, keeps track of the connections when you sent data from LAN to WAN in the last 30 seconds, and that goes to 180 seconds when the other side replies.</p>
<p>So, basically what you need to do to set up a bi-directionnal UDP connection is sending some data from the equipment to the server each 25 seconds. My guess is that even empty UDP packets (8 bytes sized packet) should work. </p>
<p>The most simple/secure way to do this (don&#8217;t forget that UDP datagrams can be dropped on their way to the server), is to establish a communication with the server in TCP. Then, ask for a unique identifier (two bytes for instance) and then use it each time you send data on UDP.</p>
<p>If you want to send data between two NATed network, it&#8217;s also possible. This <a href="http://tools.ietf.org/html/rfc5128">little RFC</a> explains it very well. If this seems a little bit to abstract, you should try out <a href="http://www.wireshark.org/">wireshark</a>. I always use it when I have a doubts about some low-level network transmission (I like to investigate a lot, just to make sure I&#8217;m not missing anything).</p>
<h3>I didn&#8217;t say it sucks</h3>
<p>It didn&#8217;t say the TC65 sucks. It&#8217;s just not as efficient as I thought it could be. The network stack doesn&#8217;t seem to have been built for performances. If you send TCP data or receive UDP data too often, there&#8217;s a pretty good chance you will face the same problems. If you found a solution to bypass these problems, please tell me how.</p>
<p>But remember, if you only need to send some data each second (or less often), which is the case in most of the M2M applications, you can be sure the chip will suit your needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/tc65-slow-udp-reception/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cinterion TC65&#8242;s TCP stack limits</title>
		<link>http://florent.clairambault.fr/cinterion-tc65s-tcp-stack-limits?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cinterion-tc65s-tcp-stack-limits</link>
		<comments>http://florent.clairambault.fr/cinterion-tc65s-tcp-stack-limits#comments</comments>
		<pubDate>Sun, 26 Apr 2009 15:15:12 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Cinterion]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[TC65]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=605</guid>
		<description><![CDATA[If you use the TC65 to transmit some frequent (with a transmission interval of less than 700 ms) data, you should know that the TC65&#8242;s has a poor TCP implementation considering the ACK management of sent messages. When the TC65 sends a TCP packet, it waits for the ACK packet of this transmitted packet before [...]]]></description>
			<content:encoded><![CDATA[<p>If you use the TC65 to transmit some frequent (with a transmission interval of less than 700 ms) data, you should know that the TC65&#8242;s has a poor TCP implementation considering the ACK management of sent messages. </p>
<p>When the TC65 sends a TCP packet, it waits for the ACK packet of this transmitted packet before sending any other packet. That means that if you have a delay 400 ms between the TC65 and your server (which is very quite common), the TC65 will wait for 800 ms (400 ms for the data packet from the TC65 to the server and 400 ms for the ACK packet to return) before sending any data.</p>
<p>I discovered it because I wanted to send real-time GPS tracking data, and at a rate of 20 positions per second it was way above the minimal delay of 800ms. My positions came by packet of 5 to 20.</p>
<p>I asked for help to the french Cinterion&#8217;s support with complete description of the problem, &#8220;AT^SCFG&#8221; complete view and some libpcap network captures. And they couldn&#8217;t give me any real solution to this problem.</p>
<p>I think this is a chosen restriction. The chip has a memory of 400 Kb, to use this the chip would have to use a more complex TCP stack and to consume some RAM to store the last not yet aknowledged messages. I might be wrong, there might be a way to activate this, but right now Cinterion isn&#8217;t able give me any answer.</p>
<p>The only solution I found is to send data from the TC65 using UDP and to receive data using TCP. And receiving in real-time (I mean short time) DOES work perfectly with the chip (no need for increasing the receive buffer). You just have to disable Nagle&#8217;s algorithm (TCP_NODELAY=TRUE) on the remote host (most probably the TCP server).</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/cinterion-tc65s-tcp-stack-limits/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/25 queries in 0.009 seconds using disk: basic
Object Caching 620/663 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 10:52:14 -->
