为什么下面的代码让我的电脑发出哔哔声? [英] Why does the following code make my computer beep?

查看:43
本文介绍了为什么下面的代码让我的电脑发出哔哔声?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解为什么这段代码让我的电脑发出哔哔声.我已将这部分代码隔离为偶尔发出哔哔声的部分,但我看不出它有什么问题.

I'm having a really hard time understanding why is this piece of code making my computer beep. I've isolated this section of code to be the one producing the occasional beep, but I don't see what's the problem with it.

const int BUFFER_LENGTH = 8192;
char buffer [BUFFER_LENGTH + 1];
int recvResult;

do
{
    recvResult = recv(webSocket, buffer, BUFFER_LENGTH, 0);
    buffer[recvResult] = '\0';
    printf("%s", buffer);
    if (recvResult > 0)
    {
        sendResult = send(clientSocket, buffer, recvResult, 0);
    }
}while (recvResult > 0);

shutdown(webSocket, SD_SEND);

提供一点上下文,这是针对计算机网络类的,我们必须在其中编写代理代码.所以我正在做的是听取答案并将其转发给客户.

To give a little bit of context, this is for a computer networks class in which we have to code a proxy. So what I'm doing is listening to the answer and simply forward it to the client.

当我第一次听到哔哔声时,我无法告诉你我从椅子上跳了多高......

I can't tell you how high I jumped out of my chair when I first heard the beeping noise...

推荐答案

缓冲区可能包含一个 '\a' 字符,它使计算机发出哔哔声.来自 5.2.2(字符显示语义):

The buffer probably contains a '\a' char which makes the computer beep. From 5.2.2 (Character display semantics) :

表示执行字符集中非图形字符的字母转义序列旨在在显示设备上产生如下操作:

Alphabetic escape sequences representing nongraphic characters in the execution character set are intended to produce actions on display devices as follows:

  • \a(警报)在不改变活动位置的情况下产生声音或可见警报.

这篇关于为什么下面的代码让我的电脑发出哔哔声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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