C # Socket-based Asynchronous Communication System-SanNiuSignal. DLL is open-source,

Source: Internet
Author: User

C # Socket-based Asynchronous Communication System-SanNiuSignal. DLL is open-source,

Reference page:

Http://www.yuanjiaocheng.net/CSharp/csharp-Static.html

Http://www.yuanjiaocheng.net/CSharp/csharp-Anonymous-method.html

Http://www.yuanjiaocheng.net/CSharp/csharp-nullable.html

Http://www.yuanjiaocheng.net/CSharp/csharp-var.html

Http://www.yuanjiaocheng.net/CSharp/csharp-linq.html

Since the release of SanNiuSignal. DLL, the user feedback is still full. To better serve everyone, I have fixed many bugs and made this DLL open-source. Next I will introduce it first.

A simple communication system developed using this DLL ;:

 

Want to use which module to start which module, can form communication with the customer; Baidu Network Disk: http://pan.baidu.com/s/1i346GML contains SanNiuSignal. DLL source code and an example of its use; if not, add the QQ group: 426414437 for communication and update later

DLL is released in the group... below is a detailed introduction to the source code of SanNiuSignal. DLL

SanNiuSignal is a completely free DLL Based on asynchronous socket. It encapsulates Client, Server, and UDP. With this DLL, you do not need to worry about heartbeat. Stick the package.
Group packages, sending files, and other complex tasks. You only need a few simple steps to implement a powerful communication system. It can help you feel the happiest thing and hope you can
Find out the deficiencies in the DLL in the Process of use; make corrections; the apple and java versions of this DLL are under development ......

The following describes how to use SanNiuSignal.

1): TCPServer. You can use the static TxStart. startServer method to register the server ITxServer. Then, you can set various properties through ITxServer.
ITxServer. StartEngine (); you can go to the demo for details. It is relatively simple. Here are some notes.
1. ITxServer. BufferSize indicates the size of the received data buffer. The default value is 1 kb, which must be the same as that of the client. Otherwise, unpredictable data may occur.
The buffer size does not affect the size of data sent each time. The size can only increase the sending speed.
2. Determine whether the IPEndPoint client is online before sending the ITxServer. sendMessage. If the client is not online, no messages are generated. For example
If the message is sent successfully and the recipient has received the message, a successful sending event is triggered;
3. You can use ITxServer. FileLog to record the running information of the server;

2): The TCPClient client is successfully registered with the client ITxClient through the static TxStart. startClient (server address or URL, server port number) method.
The ITxClient has various properties set. Finally, it starts ITxClient. StartEngine (). It is similar to the server startup. You can go to the demo to see details. The client should pay attention
Fang
1. If the client is disconnected without being forced to shut down by the server, the client will be reconnected by default. The principle is that the client will be reconnected every 10 seconds.
If ITxClient. ReconnectMax times fail, the Client Engine is automatically disabled. During the reconnection, you can change the IP address and port number of the client to connect to the server.
If you do not want to reconnect when disconnected, you can set ITxClient. ReconnectMax = 0;
2: logon. Before the engine starts, you can set ITxClient. OutTime to set the timeout time. The default value is 10 seconds, that is, there will certainly be a logon result within 10 seconds.
; Logon successful or logon failed. A logon result event is triggered;

3): Udp engine, using the static method TxStart. startUdp () to register UDP-IUdpTx; then set various attributes through IUdpTx; and finally start
IUdpTx. StartEngine (); if you want to bind a Port number before starting, set IUdpTx. Port here; otherwise, use the local Port randomly; whether it is UDP or server or
Clients; many of their methods, attributes, and events are the same, because they all inherit the basic interface ITxBase of the communication system. The following is what the UDP engine should pay attention.
1. The advantage of UDP is that it is fast but unreliable. Therefore, some attributes cannot be set too much, such as IUdpTx. BufferSize. The default value is 1 kb. If you send information on the wide area network,
The buffer size should not exceed the default value; otherwise, data will be lost. If the size of one-time data is greater than 1 kb, the system will automatically subpackage the data and will not packet loss.

4): The File Sending System uses the static FileStart. StartFileSend (IFileSendMust) method to generate a File Sending System IFileSend. Where IFileSendMust is
An interface that must be implemented. For details, refer to the demo. Then, set various attributes through IFileSend. The sending must be sent through the previous three engine systems. For example:
ITxClient. SendFile then a file tag is returned, which is an integer. IFileSend can operate on the tag to operate on the file being sent; receive the file
The same is true for the system. It also uses file tags. The same is true for file resume. The previous three communication engine systems also need to be used for resume. Because the file system cannot determine the user
Which communication system is used for resumable data transfer? For example, IUdpTx. ContinueFile can be used for resumable data transfer. You can also try again after the connection is dropped;

5): The file receiving system uses the static FileStart. StartFileReceive (IFileReceiveMust) method to generate a file receiving system IFileReceive.
IFileReceiveMust is an interface that must be implemented by the receiver. For details, refer to the demo. Then, set various attributes through IFileReceive. The following describes how to pay attention to the file system.
Key Points
1. Each file has a file tag. The sending and receiving systems control the file by controlling the tag. If the file is transmitted in the same file, the tag is the same;
2. Pay attention to the buffer size of the BufferSize attribute, which indicates the number of bytes transmitted at a time. The larger the File Buffer, the faster the transmission speed.
Debugging by yourself; TCP transmission can generally be set to relatively large, but UDP should not exceed 1 kb; therefore, try not to use UDP as unreliable as possible for transmission of large files;
3. When files are interrupted due to various reasons such as the network, the file interruption event is triggered; the file is automatically in the paused sending or receiving status; the file is to be resumed; the reseller of the resume, if the other party
Agree to resume; the other party will not trigger the start method of resume; other people can find it through demo;


Summary:
In fact, this DLL is relatively simple; you only need to master these five interfaces; 1: ITxServer TCP server interface 2: ITxClient TCP client interface 3: IUdpTx
UDP interface 4: IFileSend file sender interface 5: IFileReceive file receiver interface the first three interfaces are started through TxStart; the last two file Interfaces
Is started through FileStart

Let's talk about this first today. I hope this DLL will be helpful to you. If you have any shortcomings, I hope you can communicate with us through QQ or blog. Thank you.

This demo source code: http://pan.baidu.com/s/1i346GML contains SanNiuSignal. DLL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.