Problem using ReadFromUDP on Windows to discover local peers

xuanbao · · 496 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I wrote a library (<a href="https://github.com/schollz/peerdiscovery">schollz/peerdiscovery</a>) for discovering peers on a local network. I&#39;ve tested it with a wireless ubuntu laptop and a wired ubuntu server and it works great.</p> <p>Basically you can run the following on computer 1 and computer 2:</p> <pre><code>go get github.com/schollz/peerdiscovery cd $GOPATH/src/github.com/schollz/peerdiscovery/examples go run broadcast.go </code></pre> <p>After both are run, both computers will discover each other and the associated payload (in the example its a random payload), and they will output something like:</p> <pre><code>2018/04/22 23:59:11 discovered ip &#39;192.168.XX.XX&#39; with payload &#39;YY&#39; </code></pre> <p>But...<strong>this doesn&#39;t work on Windows</strong>! I have no idea why. If one of the computers is a Windows computer there is no activity, and no errors. I put in logging and found that Windows will get to the <a href="https://github.com/schollz/peerdiscovery/blob/master/peerdiscovery.go#L160"><code>ReadFromUDP(buffer)</code></a> and then it is unable to read anything, ever and its sent packets aren&#39;t reaching the other computers.</p> <p>Is this a Windows firewall issue? Or something else? I&#39;d love to hear any advice, thanks!</p> <p>For the record, I&#39;m using go1.10 on all computers.</p> <p><strong>Edit:</strong> Got it working with <code>golang.org/x/net/ipv4</code>, for some reason the <code>pkg/net</code> <code>ReadFromUDP</code> just didn&#39;t work.</p> <hr/>**评论:**<br/><br/>pdffs: <pre><p>Probably firewall, use WireShark or similar to see if your packets are leaving/arriving on each system.</p></pre>jerf: <pre><p>Re: </p> <blockquote> <p><strong>Edit:</strong> Got it working with <code>golang.org/x/net/ipv4</code>, for some reason the <code>pkg/net</code> <code>ReadFromUDP</code> just didn&#39;t work.</p> </blockquote> <p>If you have the time or interest, it may be worth seeing if you can figure out why.</p> <p>One trick that can help make that pretty easy is to copy the entire net package out of your Go install into a subdirectory in your code, then change all the &#34;net&#34; imports to point at your code. Then you can use print-style debugging, use go-rename to crack open unexported values and export them, and other such things freely, and figure out what&#39;s going on between the two of them. I&#39;ve found the Go standard library to be surprisingly transparent; it isn&#39;t &#34;Go all the way down&#34; but it&#39;s &#34;Go quite a long ways down&#34;. I&#39;m sure an identification of the error and a test case would be much appreciated on the bug tracker; a fix even more so. And if you&#39;ve got working code on one side and non-working code on the other, figuring out where the problem is may not be too difficult.</p></pre>Ballresin: <pre><p>I have a private repo that performs peer discovery and uses <code>golang.org/x/net/ipv4</code> as well, though I can&#39;t seem to pinpoint why I didn&#39;t try <code>pkg/net</code> first. My peer discovery code runs 99% of the time on Windows, so I could have run into the same problem, but I don&#39;t recall struggling with it.</p> <p>Commenting here in hopes I&#39;ll have time to experiment with using <code>pkg/net</code> instead and see if I can help recreate the problem and find a fix.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

496 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传