我有一个绑定到localhost UDP端口33100的sendersocket.我有一个绑定到localhost UDP端口33101的receiverocket套接字.
发送方套接字发送4500字节的数据(字符串"hello man"*500).在接收方,我有一个epoll对象,它等待receiverocket上的EPOLLIN事件.当有活动时,我会这样做:
while True:
msg_received = receiver_socket.recv(128)
if msg_received.decode("UTF-8") == "":
break
else:
print msg_received.decode("UTF-8")
Run Code Online (Sandbox Code Playgroud)
的主要问题是,我看过的前128个字节的数据后,我无法再读取.发送方表示它按预期发送了4500字节的数据.
如果发送方再次发送相同的4500字节数据,则再次注册EPOLLIN事件并读取新字符串.不知何故,在我第一次阅读后,缓冲区被清除了.
现在,即使发送者只发送了4500字节的数据,第一个recv给了我128字节的数据,然后没有任何内容recv.
我可能正在做一些非常愚蠢的事情所以请赐教.我想收到所有4500字节的数据.
假设我想打印数字args如果它们> 1或"无",如果它们<= 1.我知道如何做的唯一方法是:
cout << "number of args: ";
if (argc > 1)
cout << argc - 1;
else
cout << "none";
cout << endl;
Run Code Online (Sandbox Code Playgroud)
但后来我无法将<<运营商联系起来.理想情况下,我希望能够做到这样的事情:
cout << "number of args: "
<< argc > 1 ? argc - 1 : "none"
<< endl;
Run Code Online (Sandbox Code Playgroud)
但这是不可能的,因为来自三元的类型是不同的.
想法?
我在安装了Windows7的公司计算机上.我也在上面安装了VirtualBox,并在这个虚拟机上安装了Ubuntu.
现在,从虚拟机(Ubuntu的)里面,我可以访问公司的内部网站,我收到答复我的ping到DNS,网关和DHCP服务器,但我仍然无法ping外任何东西,或从网络浏览器访问互联网.
我的配置如下:
任何帮助都非常感谢.我已经尝试了我能想到的一切.谢谢.
我在.sh文件中编写代码并运行它...
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "2 argument required, $# provided"
echo $2 | grep -E -q '^[0-9]+$' || die "Numeric argument required, $2 provided"
nfile_location = /home/virtual/$1
if [ -f $nfile_location ];
then
chmod -R $2 $nfile_location
echo "Set permission";
exit 1;
else
echo "Not a correct file";
exit 1;
fi
Run Code Online (Sandbox Code Playgroud)
但它不起作用.它显示以下错误,我无法理解,因为我是bash脚本的新手.
/root/new_scripts/setpermission.sh: line 11: nfile_location: command not found
chmod: missing operand after `777'
Try `chmod --help' for …Run Code Online (Sandbox Code Playgroud) 我试图想出一个"单行"用于在Haskell中生成列表的排列.这是我到目前为止:
perms xs = if length xs == 0 then [[]] else [x:ys | x <- xs, ys <- perms $ delete x xs]
问题是我不得不if在Haskell中使用我不太喜欢的东西.是否可以避免使用if或多部分定义或案例陈述等,而只能使用"高阶"函数(例如foldr等)来实现这一目标?(并且理想情况下保持相对较小的单线)
bash ×1
c++ ×1
haskell ×1
linux ×1
networking ×1
python ×1
sockets ×1
ubuntu ×1
udp ×1
virtualbox ×1