<p>I wrote a library (<a href="https://github.com/schollz/peerdiscovery">schollz/peerdiscovery</a>) for discovering peers on a local network. I'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 '192.168.XX.XX' with payload 'YY'
</code></pre>
<p>But...<strong>this doesn'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't reaching the other computers.</p>
<p>Is this a Windows firewall issue? Or something else? I'd love to hear any advice, thanks!</p>
<p>For the record, I'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'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'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 "net" 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's going on between the two of them. I've found the Go standard library to be surprisingly transparent; it isn't "Go all the way down" but it's "Go quite a long ways down". I'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'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't seem to pinpoint why I didn'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't recall struggling with it.</p>
<p>Commenting here in hopes I'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
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传