Visual C # .NET Network Core Programming Notes

xiaoxiao2021-03-06  40

1. Network flow

Networkstream

Public networkStream {

Socket socket;

}

Public networkStream {

Socket socket;

Bool Ownssocket;

}

Public networkStream {

Socket socket;

FileAccess Access;

}

Public networkStream {

Socket socket;

FileAccess Access;

Bool Ownssocket;

}

EXAM:

NetWorkStream NewStream = New NetworkStream (Mesock, System.IO.FileAccess.Read, True);

Read method

Public override int {

INT BYTE [] BUFFER,

Int offset,

int size

}

EXAM:

NetWorkstream NewStream = New NetworkStream (Mesock);

Byte [] mybyte = new byte [64];

NewsTream.read (mybyte, 0, mybyte.length);

Newsteam.flush ();

Write method

Public override void write {

Byte [] buffer,

Int offset,

int size

}

2. Text stream

Write text flow to text

Streamwriter SW = NULL;

// New data replace the old data, if the parameter is TRUE, the new data is after the old data

SW = new streamwriter ("E: //temp//aa.txt", false, system.text.encoding.utf8);

SW.WRITE ("Aaaaaaaaa");

SW.CLOSE ();

Write text to the network

String str = "aaaaaaaaaaaa";

Byte [] mybyte = system.text.encoding.utf8.getbytes (STR);

NetworkStream NetStream = New NetworkStream (MySock);

NetStream.write (Mybyte, 0, Mybyte.length);

Read the text from the file

StreamReader SR = NULL;

SR = New StreamReader ("E: //TEMP//aa.txt", system.text.encoding.utf8);

String mystr = sr.readtoend ();

sr.close ();

Read text from the network

String str = "aaaaaaaaaaa";

Byte [] mybyte = system.text.encoding.utf8.getbytes (STR);

NetworkStream NetStream = New NetStream (mysock);

NetStream.read (mybyte, 0, mybyte.length);

3. File stream

Write network data into files

FileStream FileStream = New FileStream (path, filemode.openorcreate, fileaccess.write);

INT readnumber = 0;

Byte [] BYE ​​= New byte [8];

While (readnumber = stream.read (bye, 0 ,8))> 0)

{

FileStream.write (Bye, 0, ReadNumber);

FileStream.flush ();

}

FileStream.close ();

Read files to network stream

FILESTREAM FileStream = New FileStream (Path, FileMode.Openorcreate, FileAccess.Read);

Int number;

Byte [] bb = new byte [8];

NetWorkStream Stream = New NetworkStream (NewClient);

While ((Number = filestream.read (bb, 0, 8))! = 0)

{

Stream.write (BB, 0, 8);

stream.flush ();

BB = new byte [8];

}

FileStream.close ();

4. Command analysis

Filter useless characters (between commands and parameters are generally spaced in space , command to end in wrap )

BYTE [] mybyte = new byte [1024];

NetworkStream NetStream = New NetworkStream (MySock);

NetStream.read (mybyte, 0, mybyte.length);

String str = system.text.Encoding.ascii.getstring (mybyte);

INT x = str.indexof ("/ r / n");

String allcommand = str.substring (0, x);

CHAR [] a = new char [] {''};

String command.split (a);

String command = commstr [0];

STING parameter1 = commstr [1];

STING parameter2 = commstr [2];

5. Method parameters

PARAMS keyword specified number of parameters variable

EXAM:

Private void useparams (params string [] list)

{

For (int i = 0; i

{

TextBox1.AppendText (List [i] "/ r / n");

}

}

OUT keyword is mainly used to return multiple values, but also a pass reference

6. Thread

create:

Thread thread = New Thread (New ThreadStart (ACCP));

Private Void ACCP ()

{

..............

}

start up:

Thread.start ();

Pause and restart

Thread.sleep (10000) // mi

Thread.suspend (); // pause

Thread.Resume ();

destroy:

Thread.abort ();

Thread.join (10000);

Thread.join (10000);

Thread.Iterrupt ();

转载请注明原文地址:https://www.9cbs.com/read-71775.html

New Post(0)