如何在C pferably写一个简单的基于文本的协议,$ P $ [英] How to write a simple text based protocol, preferably in C

查看:246
本文介绍了如何在C pferably写一个简单的基于文本的协议,$ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写与应用服务器通过标准 TCP / IP 通信的客户端程序。客户端可以说话到应用服务器和通过简单地说在一个基于特定文本协议进行认证。该数据被加密,但不会有用户名/密码。如果其他应用程序试图与应用程序服务器进行通信,如果应用程序没有使用正确的基于文本的协议,应用服务器将丢弃数据包。

I want to write a client program that communicates with the application server via standard TCP/IP. The client can speak to the application server and be authenticated by simply speaking in a specific text based protocol. The traffic will be encrypted, but there won't be username/password. If another application tries to communicate with the application server and if the application doesn't use the correct text based protocol, the application server will silently discard packets.

等待建议。

推荐答案

您可以使用的 TLV (标签长度值)。

You can use a simplified version of TLV (Tag Length Value).

其基本思想是定义一组这是由固定的大小(T代表标签)的code psented重新$ P $消息类型。根据不同的内容之前,它的内容(V代表值)可以很让你指定它的长度(L代表长度)消息的类型。 Length字段也有固定的大小

The basic idea is to define a set of message types which are represented by a code of fixed size (the T for Tag). Depending the type of message the contents of it (the V for Value) can very so you specify its length (the L for Length) before the contents. The Length field also has fixed size

假设你有用于用户数据发送到服务器一个消息。您可以定义一个消息,如:

Suppose you have one message used to send user data to the server. You can define a message like:

0x01 0x0018 0x11 0x0003 tom 0x12 0x000F tom@hotmail.com

Tag: 0x10 User data. Length: 0x0018 Value: sub tags

    Tag 0x11: user name Length: 0x0003 Value = tom
    Tag 0x12: email. Length: 0x000F. Value = tom@hotmail.com

编辑

我要忘了:圣诞快乐:)

I was about to forget: Merry Christmas :)

这篇关于如何在C pferably写一个简单的基于文本的协议,$ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆