开发者

Protocol communication help

Using Visual Studio 2005 Language: c#

A new to c#

I have software, the software should communicate with gprs dev开发者_运维百科ices. So i want to write a protocol, TCP, UDP communication code.

Can any one give some idea for writing a source code and some sample code also.


When you say the software should communicate with GPRS devices, I'm going to assume you mean they want to communicate with eachother using TCP/IP and the fact that the two endpoints are connected to eachother by GPRS modems should make little to no difference except for that fact that you have to keep in mind the limited bandwith and slower transfer speeds.

(Some extra work does have to be done when you are using GPRS modems which are connected to your system using RS232 or USB interfaces, I'm assuming GPRS modems with a direct RJ45 connector here)

Your first step is to make sure you understand the basics of TCP/IP and UDP/IP. You did not mention what kind of data you want to exchange between the applications, so that leaves us very little to go on. You need to decide what type of messages the applications will exchange and you need to determine whether you'll use TCP/IP or UDP/IP to exchange those messages. Long story short, you should only use UDP if you can afford to lose a few bytes along the way. (For example, it doesn't matter if you lose a few frames while streaming video).

Once you've decided what kind of messages the applications should exchange, you need to determine how you will represent them. Olivier pointed out you should take a look at ProtoBuf.Net, which is a .NET implementation of the Google Protocol Buffers.

You can find more information on the topic here: http://code.google.com/intl/nl-NL/apis/protocolbuffers/docs/overview.html

Basically it allows you to define messages like this:

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

Which, by means of ProtoBuf.Net, you can then use in your code. The binary format of Google Protocol Buffers is compact enough to be transmitted over GPRS connections.

I hope this gives you a few starting points, first deside what you want, then look into the points we've mentioned and feel free to post new (more specific) questions in the future


This is just a "Give me the code" question. I would say you should start your programming and ask questions about your concrete upcoming questions.

As starting point you should take a look into System.IO.Ports.SerialPort, System.Net.Sockets and Serialization (Binary, DataContract, ProtoBuf.Net)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜