TikTok OA 面试真题解析:Network Sockets

19次阅读
没有评论

1. Network Sockets

Consider two pseudo-code snippets illustrating file transfer mechanisms between a client and a server.

Pseudo-code 1

Client:

file = openFile("localFile.txt")
chunk = readFileChunk(file)
while (chunk is not empty)
    transmitData(chunk)
    chunk = readFileChunk(file)
endWhile
closeFile(file)

Server:

file = createFile("receivedFile.txt")
while (dataAvailable())
    chunk = receiveData()
    writeFileChunk(file, chunk)
endWhile
closeFile(file)

Pseudo-code 2

Client:

file = openFile("localFile.txt")
data = readEntireFile(file)
transmitData(data)
closeFile(file)

Server:

data = receiveDataUntilComplete()
file = createFile("receivedFileComplete.txt")
writeEntireFile(file, data)
closeFile(file)

Which of the following statement(s) are true?

Pick ONE OR MORE options.

这道题考察的是文件传输中的分块传输与整文件传输两种设计思路。Pseudo-code 1 是典型的 chunked transfer:客户端按块读取并发送,服务端按块接收并写入,适合大文件、内存受限或网络不稳定的场景。Pseudo-code 2 则是一次性把整个文件读入内存再发送,服务端也需要等待完整数据后再落盘,代码更简单,但对大文件不友好。做题时重点区分“是否流式处理”“是否需要完整结束信号”“是否依赖额外协议 / 元数据来判断传输完成”。

正文完
 0