<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>WebSocket on Prateek Sharma</title>
		<link>https://prateeksharma.me/tags/websocket/</link>
		<description>Recent content in WebSocket on Prateek Sharma</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Sat, 29 Aug 2026 00:00:00 +0000</lastBuildDate>
		
			<atom:link href="https://prateeksharma.me/tags/websocket/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Daemon threads for WebSocket keepalives</title>
				<link>https://prateeksharma.me/notes/daemon-threads-for-websocket-keepalives/</link>
				<pubDate>Sat, 29 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/notes/daemon-threads-for-websocket-keepalives/</guid>
				<description>&lt;p&gt;A WebSocket connection that needs periodic pings to stay open shouldn&amp;rsquo;t run that&#xA;ping loop on a plain, non-daemon thread. In the&#xA;&lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-java/&#34;&gt;WazirX Java connector&lt;/a&gt;&#xA;, the ping thread is&#xA;started &lt;code&gt;onOpen&lt;/code&gt; and marked &lt;code&gt;setDaemon(true)&lt;/code&gt; before starting it:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#e6edf3;background-color:#0d1117;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pingThread&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72;font-weight:bold&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;new&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;Thread(&lt;span style=&#34;color:#ff7b72&#34;&gt;new&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;PingMessage(&lt;span style=&#34;color:#ff7b72&#34;&gt;this&lt;/span&gt;));&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pingThread.setDaemon(&lt;span style=&#34;color:#79c0ff&#34;&gt;true&lt;/span&gt;);&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pingThread.start();&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A non-daemon thread keeps the JVM alive until it finishes. If a caller opens a&#xA;socket, forgets to close it, and the rest of the application shuts down, a&#xA;non-daemon ping thread will keep the process running indefinitely. A daemon&#xA;thread just gets killed when everything else is done — which is the right&#xA;default for background keepalive work that isn&amp;rsquo;t itself the point of the&#xA;program.&lt;/p&gt;</description>
			</item>
			<item>
				<title>WazirX Java Connector</title>
				<link>https://prateeksharma.me/projects/wazirx-connector-java/</link>
				<pubDate>Sun, 23 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/projects/wazirx-connector-java/</guid>
				<description>&lt;p&gt;After building the &lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-go/&#34;&gt;Go connector&lt;/a&gt;&#xA; for WazirX, I&#xA;wanted the same thing on the JVM — but WazirX doesn&amp;rsquo;t publish an official Java&#xA;client at all, REST or WebSocket. The REST half was a fairly direct port of what&#xA;I&amp;rsquo;d already learned building the Go client. The WebSocket half turned out to be&#xA;its own project.&lt;/p&gt;&#xA;&lt;h2 id=&#34;letting-callers-choose-their-failure-granularity&#34;&gt;Letting callers choose their failure granularity&lt;/h2&gt;&#xA;&lt;p&gt;For errors, I didn&amp;rsquo;t want every caller forced into one giant catch-all&#xA;exception, but I also didn&amp;rsquo;t want to force a &lt;code&gt;try/catch&lt;/code&gt; at every single call&#xA;site. I split errors into two, with one extending the other:&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
