<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>TCP粘包问题 on 知识铺的博客</title>
    <link>https://index.zshipu.com/geek001/tags/TCP%E7%B2%98%E5%8C%85%E9%97%AE%E9%A2%98/</link>
    <description>Recent content in TCP粘包问题 on 知识铺的博客</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-CN</language>
    <lastBuildDate>Mon, 06 May 2024 02:11:32 +0000</lastBuildDate>
    <atom:link href="https://index.zshipu.com/geek001/tags/TCP%E7%B2%98%E5%8C%85%E9%97%AE%E9%A2%98/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>使用消息边界标记解决TCP粘包问题的示例代码</title>
      <link>https://index.zshipu.com/geek001/post/20240505/%E4%BD%BF%E7%94%A8%E6%B6%88%E6%81%AF%E8%BE%B9%E7%95%8C%E6%A0%87%E8%AE%B0%E8%A7%A3%E5%86%B3TCP%E7%B2%98%E5%8C%85%E9%97%AE%E9%A2%98%E7%9A%84%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81--%E7%9F%A5%E8%AF%86%E9%93%BA/</link>
      <pubDate>Mon, 06 May 2024 02:11:32 +0000</pubDate>
      <guid>https://index.zshipu.com/geek001/post/20240505/%E4%BD%BF%E7%94%A8%E6%B6%88%E6%81%AF%E8%BE%B9%E7%95%8C%E6%A0%87%E8%AE%B0%E8%A7%A3%E5%86%B3TCP%E7%B2%98%E5%8C%85%E9%97%AE%E9%A2%98%E7%9A%84%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81--%E7%9F%A5%E8%AF%86%E9%93%BA/</guid>
      <description>下面是一个简单的示例，演示如何使用消息边界标记解决 TCP 粘包问题。在这个示例中，消息边界标记是换行符 \n。 服务端代码： import java.io.*; import java.net.*; public class TCPServer { public static void main(String[] args) { final int PORT = 8888; try { ServerSocket serverSocket = new ServerSocket(PORT); System.out.println(&amp;#34;Server started...&amp;#34;); while (true) { Socket clientSocket = serverSocket.accept(); System.out.println(&amp;#34;Client connected: &amp;#34; + clientSocket); // 创建一个新线程处理客户端连接 Thread clientThread = new Thread(new ClientHandler(clientSocket)); clientThread.start(); } } catch (IOException e) { e.printStackTrace(); } } } class ClientHandler implements Runnable { private Socket clientSocket; public ClientHandler(Socket clientSocket)</description>
    </item>
  </channel>
</rss>
