Recently a project to use point file transmission, I find information everywhere to write procedures, and finally completed, in order to let others take less detours, I decided to the most important part of the program to contribute out, I hope to help.
My program is divided into three parts, including the sending part, the acceptance part and a shared communication base class, this base class is my painstaking crystallization:
First, the communication base class
Using System;
Using System.Net.Sockets;
Using System.Net;
Using System.IO;
Using System.Windows.Forms;
Using System.Text;
Namespace BaseClass
{
<summary>
The format of the message is the command part of a given length + the command annotation section of a given length + variable length information + variable length information section
</summary>
public class Communclass
{
Public Communclass ()
{
//
TODO: Add constructor logic here
//
}
<summary>
Length of the command section
</summary>
private static readonly int cmdlen = 50;
<summary>
Length of the command annotation section
</summary>
private static readonly int desclen = 100;
<summary>
The length of the variable length information part of the number of bytes
</summary>
private static readonly int dynamiclengthlen = 10;
<summary>
Length of the Variable information section per process
</summary>
private static readonly int deallen = 1024;
<summary>
/answer Maximum length
</summary>
private static readonly int responlen = 20;
<summary>
Character used to populate a command or comment less than part of the length
</summary>
private static readonly char Fillchar = ' ^ ';
<summary>
A callback method (also considered a trigger event, but not strictly) after a successful sending of a portion of data
</summary>
public delegate void OnSend (int itotal,int isending);
<summary>
Establish a connection based on the given server and port number
</summary>
<param name= "Strhost" > Server name </param>
<param name= "Iport" > Port number </param>
<returns></returns>
public static Socket Connecttoserver (String strhost,int iport)
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.