新手问题 本人自行删除

lanjingyu · November 18, 2015 · Last by windwiny replied at November 19, 2015 · 3206 hits

本人自行删除

帮你用 code block 格式化了一下。

2 Floor has deleted
3 Floor has deleted
require 'socket'
# s1 server ,s2 client 
s1, s2 = Socket.pair(:INET, :STREAM, 0)
s1.send "ab", 0
s1.close
p s2.recv(10) #=> "ab"

试试这个。

应该给出 server 端的代码才能判断。

感觉得应该是写的长度不够,而 server 端需要读取指定长度的数据而阻塞了,所以#3 的 read 超时了。当然如果 server 端用 EOF 判断的话就不大对啦。

而且你给的那个 c 的 write 也感觉奇怪。如果 char_array 做为数组用的话 sizeof 不应该 -1(或者应该是上方有个变量保存实际数据大小),如果做为字符串用的话应该用 strlen

6 Floor has deleted
7 Floor has deleted

recv 有指定长度的,也有超时时间参数

9 Floor has deleted
lanjingyu closed this topic. 02 Jul 10:21
You need to Sign in before reply, if you don't have an account, please Sign up first.