Netty - UDP服务器(Netty - UDP server)

我有一个基于UDP Netty的服务器。 它有一个SimpleChannelUpstreamHandler流水线,我重写messageReceived方法。

我需要不时写回一些信息。 我只能通过使用MessageEvent.getRemoteAddress()的套接字信息和MessageEvent.getRemoteAddress()的通道来完成此操作。 为了能够重复使用这些信息,我保存在一张静态地图中。

这将变成MessageEvent.getChannel().write("foo", MessageEvent.getRemoteAddress());

我所期望的是让MessageEvent.getChannel().getRemoteAddress()工作,事实并非如此。 它总是给我null

  1. 难道我做错了什么 ?
  2. 在保留某些成员的频道和远程地址的情况下,是否有更好的写回方式?

I am having an UDP Netty based server. It has a SimpleChannelUpstreamHandler pipelined where I override the messageReceived method.

I need to write back some information now and then. I could only do that by using the socket information from MessageEvent.getRemoteAddress(), and the channel from MessageEvent.getChannel(). In order to be able to reuse this information I keep in in a static map.

This turns into MessageEvent.getChannel().write("foo", MessageEvent.getRemoteAddress());

What I would have expected was to have MessageEvent.getChannel().getRemoteAddress() work, which is not the case. It always gives me null.

  1. Am I doing something wrong ?
  2. Is there a better way for writing back than keeping the channel and remote address in some member ?

原文:https://stackoverflow.com/questions/17321850
2022-06-16 19:06

满意答案

入口点RVA,入口点原始地址和图像基址以这种方式不相关。

图像库是“当它加载到存储器中时图像的第一个字节的首选地址”。 换句话说,假设没有冲突,它是加载时图像的虚拟地址。 如果在加载图像时存在地址冲突(例如,已经在重叠范围中加载了另一图像),则将为图像选择新的基地址。

RVA是相对虚拟地址。 它是“相对的”,因为它在实际加载图像时会发生变化。 它是未知基址的地址(例如,未加载图像时)。 加载映像后,RVA将成为虚拟地址(VA),即虚拟内存中的实际地址。

原始与RVA的区别在于对齐。 部分对齐(部分在加载到内存时对齐)以及文件对齐(部分中原始数据的对齐)。 这里的节对齐是0x1000,而文件对齐是0x200。

入口点RVA用于确定加载图像时入口点的VA(即入口点将位于虚拟地址EntryPoint (rva) + ImageBase )。 入口点原始地址是入口点所在文件的偏移量。

本文档对齐有很好的解释。


The entry point RVA, entry point raw address, and image base address are not related in that way.

The image base is the "preferred address of the first byte of the image when it is loaded in memory". In other words, it's the virtual address of the image when it gets loaded assuming there's not a conflict. If there is an address conflict when the image is loaded (e.g. another image is already loaded in an overlapping range), then a new base address will be chosen for the image.

An RVA is a relative virtual address. It is "relative" in the sense that it is changed when the image is actually loaded. It's the address when the base address is not known (e.g. when the image isn't loaded). Once the image is loaded, the RVA becomes a virtual address (VA), an actual address in virtual memory.

The raw vs. RVA distinction is due to alignment. There is section alignment (the alignment of the sections when they get loaded into memory) as well as file alignment (the alignment of the raw data in the sections). The section alignment here is 0x1000 while the file alignment is 0x200.

The entry point RVA is used to determine the VA of the entry point when the image is loaded (i.e. the entry point will be located at virtual address EntryPoint (rva) + ImageBase). The entry point raw address is the offset into the file where the entry point is located.

This document has a good explanation of alignment.

相关问答

更多

汇编中每个NetModule的PE标头(PE Header for Each NetModule in Assembly)

必须通过al.exe链接al.exe才能创建可用的程序集。 链接器的工作是在程序集中生成元数据的最终版本。 独一无二的。 .netmodules must be linked by al.exe to create a usable assembly. It's the linker's job to generate the final version of the metadata in the assembly. The one and only.

如何读取内存中加载的模块的PE头?(How do I read the PE header of a module loaded in memory?)

这是PE文件格式的一个很好的起点。 您可以从基地址P /调用ReadProcessMemory ,以将头复制到您的过程中。 你需要解析你读入各种PE头的内存。 第一个标题是IMAGE_DOS_HEADER ,它将指向IMAGE_NT_HEADERS 。 然后,您可以使用IMAGE_NT_HEADERS中的IMAGE_OPTIONAL_HEADER来查找二进制文件中IMAGE_EXPORT_DIRECTORY的位置。 This is a good starting point for the PE ...

PE:在.txt部分末尾添加代码(PE: Adding code at the end of .txt section)

这是一个很好的问题,并说明了Windows加载程序如何计算内存大小的一个非常重要的观点(或者你可能会说是怪癖)。 PE / COFF规范确实将VirtualSize描述为“加载到内存中时节的总大小”。 如果您认为total是包含该部分的REAL数据的总量,那么这在技术上是正确的,但它不是Windows为该部分分配的内存总量。 您会发现VirtualSize通常比Windows为内存中的部分分配的数量少,因为VirtualSize必须四舍五入到最近的内存对齐值(在PE映像中设置)。 换句话说,Vir...

如何理解此图中的PE头?(How to understand the PE header in this graph?)

入口点RVA,入口点原始地址和图像基址以这种方式不相关。 图像库是“当它加载到存储器中时图像的第一个字节的首选地址”。 换句话说,假设没有冲突,它是加载时图像的虚拟地址。 如果在加载图像时存在地址冲突(例如,已经在重叠范围中加载了另一图像),则将为图像选择新的基地址。 RVA是相对虚拟地址。 它是“相对的”,因为它在实际加载图像时会发生变化。 它是未知基址的地址(例如,未加载图像时)。 加载映像后,RVA将成为虚拟地址(VA),即虚拟内存中的实际地址。 原始与RVA的区别在于对齐。 部分对齐(部分...

PE标头的大小(The size of a PE Header)

您可以像这样计算PE头的总大小: sizeof(Signature) + sizeof(FileHeader) + sizeof(OptionalHeader) + sizeof(SectionTable) 文件头总是具有相同的大小,但OptionalHeader的大小可以不同,部分表大小也是如此。 OptionalHeader的大小存储在FileHeader.SizeOfOptionalHeader ,而section表大小等于FileHeader.NumberOfSections * siz...

如何读取过滤器驱动程序中当前进程的PE头(How read PE header of current process in filter driver)

我建议在创建过程时获取此信息。 您可以在创建新进程时通知PsSetCreateProcessNotifyRoutine(Ex) 。 当PE文件(包括进程'主可执行文件)映射到虚拟地址空间时, PsSetLoadImageNotifyRoutine通知您。 当进程完全初始化并运行时,从进程的内存中读取版本信息是一个坏主意。 该进程可以完全控制其PE文件映射,因此可以伪造版本信息。 更重要的是,您只能在低IRQL(PASSIVE_LEVEL)下访问用户模式内存。 可以在APC_LEVEL / DISP...

为什么我的PE文件无效?(Why is my PE file invalid?)

你肯定是从错误的一端解决这个问题。 破解十六进制并不会让你得到你想要的东西,PE文件结构太复杂了。 你需要两件事。 Matt Pietrek的开创性文章是理解结构的必要读物。 在了解至少75%的代码之前,不要开始使用代码。 您需要Windows SDK。 include / winnt.h文件包含PE格式中使用的结构的声明。 它从_IMAGE_DOS_HEADER开始,这是文件的第一个块。 编写代码以从其声明中创建结构,这是获得有效可执行文件的唯一方法。 PS:您的十六进制转储挂起了试图查看您的问...

PE .idata部分(PE .idata section)

实际上,在我刚刚构建的可执行文件中,没有.idata部分。 使用PE Explorer,我们可以看到Import Table和IAT存储为.rdata部分的一部分。 (注意“指向目录”栏): 在Data Directories页面上,我们看到Import Table的虚拟地址是0x403354 。 这落在.rdata部分( 0x403000 - 0x403C00 )的范围内。 有趣的是(有点令人沮丧),IDA的PE加载器综合“创建”了一个实际上不存在于文件中的.idata部分: Indeed, i...

是否为DLL模块评估了PE头和LARGEADDRESSAWARE?(PE header and LARGEADDRESSAWARE not evaluated for DLL modules?)

是否真的是Windows操作系统仅为父可执行文件评估此标志的情况? 是。 是否完全忽略了所有DLL模块? 是。 那么,如果没有人在评估它,为什么我应该为DLL启用LAA链接器标志? 你不应该。 这样做毫无意义。 我记得以下内容:如果启用LAA的exe加载未编译为LAA的模块,是否有办法强制Windows发出警告? 不,那里没有。 问题是堆是进程广泛的。 它由所有模块共享。 你不能让一些人使用LAA堆而其他人不能。 所以只有可执行文件才有机会做出这个决定。 该标志采用PE文件格式,这对于DLL和EX...

为什么存储在PE文件中的值是反向的?(Why value stored in PE file is reverse?)

PE格式是Little Endian ,因此最不重要的字节是第一个。 PE format is Little Endian, so the least-significant byte is first.

相关文章

更多

[Netty 1] 初识Netty

1. 简介 最早接触netty是在阅读Zookeeper源码的时候,后来看到Storm的消息传输层也由 ...

Netty源码分析

Netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户 ...

Netty入门实例-编写服务器端程序

channelRead()处理程序方法实现如下

Netty入门实例-时间服务器

Netty中服务器和客户端之间最大的和唯一的区别是使用了不同的Bootstrap和Channel实现

基于C#的UDP协议的同步实现

一、摘要   总结基于C#的UDP协议的同步通信。 二、实验平台   Visual Studio ...

Netty环境配置

netty是一个java事件驱动的网络通信框架,也就是一个jar包,只要在项目里引用即可。

Netty开发环境配置

最新版本的Netty 4.x和JDK 1.6及更高版本

LeetCode:Word Break(DP)

题目地址:http://oj.leetcode.com/problems/word-break/ 简单 ...

storm学习之Netty代替ZMQ

整理自 http://www.csdn.net/article/2014-08-04/2821018/ ...

Netty基于流的传输处理

​在TCP/IP的基于流的传输中,接收的数据被存储到套接字接收缓冲器中。不幸的是,基于流的传输的缓冲器 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本