简体   繁体   English

在Netty中发送和接收不同类型的对象

[英]Send and receive different types of object in netty

I am building an application in Netty which will allow people to download and upload file. 我正在Netty中构建一个应用程序,它将允许人们下载和上传文件。 But before that they should be able to log into the server. 但是在此之前,他们应该能够登录服务器。 Once they log in they can download or upload the file. 他们登录后即可下载或上传文件。

Issue I am having is how will I know the data I have received is a string(username password string) or a chunked file(as I send files as ChunkedFile) or any other java object. 我遇到的问题是如何知道接收到的数据是字符串(用户名密码字符串)还是分块文件(当我以ChunkedFile形式发送文件时)或任何其他Java对象。 How will I properly get them to original form. 我将如何正确地将它们恢复为原始形式。 I know we can use encoder and decoders but there are no proper example available which shows anything close to the problem I am having? 我知道我们可以使用编码器和解码器,但是没有合适的示例可以显示与我遇到的问题接近的任何内容?

Thanks 谢谢

Send a POST http request with Headers 发送带有标头的POST http请求

   // Prepare the HTTP request.
            FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uriJson.toASCIIString());
          request.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");

            ByteBuf  buf = Unpooled.copiedBuffer(data, CharsetUtil.UTF_8);
            request.content().writeBytes(buf);
            request.headers().set(CONTENT_LENGTH,request.content().readableBytes());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM