Beginner C #-A summary of learning notes

Source: Internet
Author: User

Learned a lot and did some exercises.

First, C # WinForm Socket

1, the main part of the program only use the Panel, Picturebox, Label, richeditbox four components, scroll bar, edit box and so on are custom, it should be easier to see clearly.
2, the server set the address is 192.168.0.103, the port is set to 5188, the client points to the server is also this address, according to the need to modify their own.
Service side:
Listening port
private int port = 51888;
Private TcpListener MyListener;
ArrayList messlist = new ArrayList ();
int messcount = 0;
...
...
ipaddress[] Addrip = dns.gethostaddresses ("192.168.0.103"); IP Address
localaddress = addrip[0];
Client:
Establish network communication
Try
{
Client = new TcpClient ("192.168.0.103", 51888); Define server-side IP addresses and ports, consistent with server-side definitions
Tcpinfo.appendtext ("Native endpoint:" Client. Client.localendpoint); IP address and port number for this machine
Tcpinfo.appendtext ("Successful connection with Server");
Linkflag = true;
}
Catch
{
Tcpinfo.appendtext ("Connection to Server failed");
Return
}
3, the program must first run the "Server" ChatServer.exe, click "Start Listening", and then run the "client" executable file, the user name from a random, password to fill. Each logged-on user on the server opens 1 threads, and the client opens 1 threads for data interaction.
4, Data transmission definition:
string[] Sarray = Getmess.split (new char[6] {' [', '] ', ' $ ', ' $ ', ' $ ', ' $ '});
SARRAY[1] Send information to the user's IP
SARRAY[3] Send a message to the section
SARRAY[4] sending the contents of a message
SARRAY[5] User Name
SARRAY[6] Time
The server distributes the messages accordingly, and the client classifies them according to the message returned.
5, because the use of drawing function, will produce a screen flicker, so the way to create a bitmap processing, to reduce flicker. Information updates may be slow or incoherent because the entire data action is written over the right. At the same time, because the original component cannot be added on the thread, the data information display is updated according to the change of the right content:
private void Tcpinfo_textchanged (object sender, EventArgs e)
{.........}
Drawing processing:
......
Bitmap Localbitmap = new Bitmap (Conter_panel. Width, Conter_panel. Height);
Graphics bitmapgraphics = Graphics.fromimage (Localbitmap);
Bitmapgraphics.clear (BackColor);
Bitmapgraphics.smoothingmode = Smoothingmode.antialias;
Draw (Conter_panel. ClientRectangle, Bitmapgraphics, 0, True, 0, Color.FromArgb (90, 143, 0), Color.FromArgb (+ 143);
Conter_panel. BackgroundImage = Localbitmap;
Conter_panel. Controls.Add (RC);
......
6, the program in order to learn the convenience of not using the database, all data interaction is put in memory.

Second, WinForm network disk (full-format audio and video online preview)

In fact, on a simple three layer, the client connects to the database through the server, and the server reads and writes the database to the client.

1. Program function:
Using VLC's Media Library (DLL), the program server supports most audio, video and other formats of preview, open the file as a local folder, the video, audio and other folders and EXE files together;
The client supports online preview, download, and upload various types of files to the server in most formats such as audio, video, etc.
Video files:
. asf;. Avi;. DivX,. DV;. flv;. GXF;. M1V;. M2V;. M2ts;. M4V;. mkv;. mov;. mp4;. MPEG;. MPEG1;. MPEG2;. MPEG4;. mpg
. mts;. MXF;. TS;. VOB;. wmv;. M4A;. M4P;. MoD WEBM;RAW;RM;RMVB;
Audio files:
. mp1;. MP2;. mp3;. WAV;. A52;. AAC;. AC3;. DTs
. FLAC;. Ogg;. OGM;. Mka
To avoid deviations, force the filename, play with MP4 and MP3, let VLC to identify itself, such as 1234.avi.mp4,123.wav.mp3.
Image file:
. bmp;. Bid;. JPG;. JPEG;. JFIF;. GIF;. TIF;. TIFF;. PNG;. Ico
2. Database:
Use sql2008, attach the database file up on it, batch file processing, write 2 scalar value functions and stored procedures, through the program pass parameters call stored procedures to record batch processing, cascading relationship to look at the database diagram.
3. Configuration:
In addition to sql2008, deploying IIS, pointing the directory to the path containing the server-side EXE files and folders, setting up anonymous access is fine, and other features are basically unused.
In the program to set your own SQL password, the user for the Sa;iis, the client, the server IP is set to 192.168.0.103 port 518888, according to the needs of their own modification, note that the changes may be more than one file to modify the IP.
4. Other Notes:
The server is a 64-bit program, you can also change to 32-bit, you need to replace the DLL file with 32-bit, the project properties Select "Preferred 32-bit", the client is 32-bit, you can select 64-bit, replace the 64-bit DLL file, the project properties remove the "preferred 32-bit." Play progress bar and playback control did not do, the program has comments, or Baidu VLC related information. VLC 32-bit, 64-bit 2.24 version, is currently the latest version, focus on VLC website update.
5, the content of the exercise:
CPU, memory monitoring, local media file playback, network streaming, WinForm file remote download, WinForm socket file upload, etc.
Access to the server file with 2 ways, HTTP and socket, upload files We do not refer to the example of Baidu, what WebClient, HTTP class, WinForm aspx what, the vast majority of use, can use the old problem, don't bother, Only refer to the socket file upload article on it, don't detours.
Client program upload every 20k, feel slow to change their own. There is a problem, upload files over 500M service end will hang off, because C # frombase64string leaked, can be used byte[] merge the way to solve the problem, please handle it yourself, other conversion methods do not try, do not support the format of the image and audio and video.

Users: 16000 to 16010, password 1234546, first add a file with the server, or the client will not open.

Download: Https://pan.baidu.com/s/1slxZwVN

There are errors in the program, not modified, just a few exercises.

Beginner C #-A summary of learning notes

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.