linux - 我如何在 Linux 中使用 "interconnect"两个套接字?

标签 linux networking sockets

有两个连接的套接字。如何互连它们?

  1. 出现在一个套接字上的数据应该写入另一个套接字。
  2. EOF/FIN 应该传播良好。如果一个是半封闭的,那么另一个也应该是半封闭的。
int client = get_connected_client_socket();
int proxy = get_connected_proxy_socket();
negotiate_with_proxy(proxy);
iterconnect(client, proxy); 
// Now forgot about both client and proxy. 
// System should handle IO/shutdown/close. 
// Ideally even without any support of the user-space process.

Linux可以吗?是否可以通过欺骗连接跟踪来改变现有连接的跟踪状态来完成?

@related Determine how much can I write into a filehandle; copying data from one FH to the other

最佳答案

你知道splice()吗? .根据你的两个问题,我认为这就是你要去的地方。最后我检查了你不能在一个拼接调用中执行此操作,因为两个文件描述符都不能是套接字。但是你应该能够在 2 个调用中完成它(sockin->pipe->sockout)。另请查看 tee() .这些可能不完全是您想要的,但据我所知,它们都在大概范围内。

关于linux - 我如何在 Linux 中使用 "interconnect"两个套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2677262/

相关文章:

linux - linux命令访问连接到嵌入式PC的USB内存棒?

linux - 如何在命令中写命令

windows - Windows 上网络接口(interface)准备就绪时的通知

java - 通过套接字发送时 Jar 文件被损坏

c - 写入该文件时来自单个文件的多个缓冲输入流?

networking - 公共(public)IP范围可以用作私有(private)IP吗?

android - 开发可与模拟器或手机一起使用的网络应用程序的最佳方法

java - 客户端如何处理 "unable to create new native thread exception"

C# 异步套接字 : How much data does the Socket store when the call to BeginReceive is delayed?

linux - bash 脚本 : combine var=$(. ..) 和 var=${var%%...} 行?