doutang1946 2017-09-01 17:47
浏览 75
已采纳

如何在L3网络层上收听?

I am creating a chat application backend and want to take into consideration the scalability.

I wanted to create a load balancer but not on the L7 layer where HTTP is located, but on the L3 layer where IP network is located to direct connections to the specific servers where I can then make TCP.

Is net.ListenIP the correct function to use to listen to the packets on the IP layer?

Is it the same as the higher Listen("tcp") for example? Is it the right method that I need to implement the load balancer?

Is there a reference to how the packet is structured so I am able get out from it the source and destination IPs to forward them?

If not tell me which function to use to listen on the L3 network layer to balance the loads to other servers.

  • 写回答

2条回答 默认 最新

  • dsf22567 2017-09-01 18:24
    关注

    After reading the Docs, yes this function will help you receive IP Packets.

    ListenIP acts like ListenPacket for IP networks.

    ListenIP is similar to ListenPacket("tcp") but for IP packets.

    As for the structure of IP packets, and working with them, the net package doesn't seem to have that.

    There's another package gopacket which looks like it will be able to help you read and modify packets from any layer.

    In gopacket there is a Packet type, which allows working with the network layer.

    Packet.NetworkLayer().LayerContent() and Packet.NetworkLayer().LayerPayload() will each return byte[] which you can interpret by the expected structure of an IP packet.


    Note: Now that I've written this whole thing I have to imagine somebody out there has written a nice overlay/wrapper to make this easier. This is just the result of me Googling for 10 minutes. Maybe somebody else will answer with a better tool/method

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题