去写插座 - 无效的参数 [英] Go writing to socket - invalid argument

查看:221
本文介绍了去写插座 - 无效的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写在Go TCP套接字,但只有收到无效参数与此code:

  _,ERR:= conn.Write([]字节(测试))
如果犯错!= {为零
    fmt.Println(err.Error())
}


解决方案

下面是你想要做什么一个简单的示例(也许?),要知道,你应该做一个TCP服务器监听的端口 8999 第一次运行前,

  NC -l 8999 #OR也许NC -l -p 8999

code:

 主包进口(
    净
)FUNC的main(){
    康涅狄格州,_:= net.Dial(TCP,本地主机:8999)
    conn.Write([]字节(测试))
}

如果这不是你的问题,你应该提供更多的信息。

Im trying to write to a TCP socket in Go but only receive "invalid argument" with this code:

_, err := conn.Write([]byte("test"))
if err != nil {
    fmt.Println(err.Error())
}

解决方案

Here is a simple sample of what you want to do(maybe?), be aware that you should make a tcp server listen to the port 8999 first before run it

nc -l 8999     #or maybe nc -l -p 8999 

code:

package main

import (
    "net"
)

func main() {
    conn, _ := net.Dial("tcp", "localhost:8999")
    conn.Write([]byte("test"))
}

If it's not your question, you should provide more information.

这篇关于去写插座 - 无效的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆