Что такое findslide.org?

FindSlide.org - это сайт презентаций, докладов, шаблонов в формате PowerPoint.


Для правообладателей

Обратная связь

Email: Нажмите что бы посмотреть 

Яндекс.Метрика

Презентация на тему Сокеты

Содержание

Со́кеты (англ. socket — углубление, гнездо, разъём) — программный интерфейс для обеспечения обмена данными между процессами.
.NET SocketСергеев Николай КБ-401 Со́кеты (англ. socket — углубление, гнездо, разъём) — программный интерфейс для обеспечения обмена данными между процессами. Сокет Беркли СерверныеКлиентские System.Net System.Net.SocketsWindows SocketsДуплексное взаимодействие SocketСинхронная передачаАсинхронная передача Socket sock = new Socket(AddressFamily.InterNetwork,  				  SocketType.Stream,  				  ProtocolType.Tcp);Конструктор Асинхронные методыConnectAsync SendAsync ReceiveAsync Shutdown Close  SocketAsyncEventArgs …SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint( …SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint( CallBack static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes( private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes( private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes( private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes( private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes( private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes( static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as Socket; private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as Socket; private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as Socket; private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as Socket; static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect: 				ProcessConnect(e);				break; private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; Этапы выполнения асинхронной операцииВыделите  SocketAsyncEventArgsЗадайте свойства объекта SocketAsyncEventArgs, Вызовите соответствующий метод сокета.Функции обратного Спасибо за внимание!
Слайды презентации

Слайд 2 Со́кеты (англ. socket — углубление, гнездо, разъём) — программный интерфейс для обеспечения обмена

Со́кеты (англ. socket — углубление, гнездо, разъём) — программный интерфейс для обеспечения обмена данными между процессами.

данными между процессами.


Слайд 3 Сокет Беркли
Серверные
Клиентские

Сокет Беркли СерверныеКлиентские

Слайд 4 System.Net

System.Net

Слайд 5 System.Net.Sockets
Windows Sockets
Дуплексное взаимодействие

System.Net.SocketsWindows SocketsДуплексное взаимодействие

Слайд 6 Socket
Синхронная передача
Асинхронная передача

SocketСинхронная передачаАсинхронная передача

Слайд 7 Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,

Socket sock = new Socket(AddressFamily.InterNetwork, 				 SocketType.Stream, 				 ProtocolType.Tcp);Конструктор

ProtocolType.Tcp);
Конструктор


Слайд 8 Асинхронные методы
ConnectAsync 
SendAsync 
ReceiveAsync 
Shutdown 
Close 

Асинхронные методыConnectAsync SendAsync ReceiveAsync Shutdown Close 

Слайд 9 SocketAsyncEventArgs

SocketAsyncEventArgs

Слайд 10
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);


Слайд 11
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);
...

Слайд 12
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);


Слайд 13
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);


Слайд 14 Функция обратного вызова

Функция обратного вызова

Слайд 15
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);


Слайд 16
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);


Слайд 17
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();

DnsEndPoint hostEntry =

…SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs(); DnsEndPoint hostEntry = new DnsEndPoint(

new DnsEndPoint("http://www.google.com", 80);

socketEventArg.Completed += new EventHandler(SocketEventArg_Completed);

socketEventArg.RemoteEndPoint = hostEntry;



socketEventArg.UserToken = sock;

sock.ConnectAsync(socketEventArg);


Слайд 18 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 19 CallBack

CallBack

Слайд 20 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 21 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 22 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 23 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 24 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 25 private static void ProcessConnect(SocketAsyncEventArgs e)
{

byte[] buffer

private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes(

= Encoding.UTF8.GetBytes("Hello World"); e.SetBuffer(buffer, 0, buffer.Length);
Socket sock =

e.UserToken as Socket;
bool willRaiseEvent = sock.SendAsync(e);
if (!willRaiseEvent)
{
ProcessSend(e);
}

}

Слайд 26 private static void ProcessConnect(SocketAsyncEventArgs e)
{

byte[] buffer

private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes(

= Encoding.UTF8.GetBytes("Hello World"); e.SetBuffer(buffer, 0, buffer.Length);
Socket sock =

e.UserToken as Socket;
bool willRaiseEvent = sock.SendAsync(e);
if (!willRaiseEvent)
{
ProcessSend(e);
}

}

Слайд 27 private static void ProcessConnect(SocketAsyncEventArgs e)
{

byte[] buffer

private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes(

= Encoding.UTF8.GetBytes("Hello World"); e.SetBuffer(buffer, 0, buffer.Length);
Socket sock =

e.UserToken as Socket;
bool willRaiseEvent = sock.SendAsync(e);
if (!willRaiseEvent)
{
ProcessSend(e);
}

}

Слайд 28 private static void ProcessConnect(SocketAsyncEventArgs e)
{

byte[] buffer

private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes(

= Encoding.UTF8.GetBytes("Hello World"); e.SetBuffer(buffer, 0, buffer.Length);
Socket sock =

e.UserToken as Socket;
bool willRaiseEvent = sock.SendAsync(e);
if (!willRaiseEvent)
{
ProcessSend(e);
}

}

Слайд 29 private static void ProcessConnect(SocketAsyncEventArgs e)
{

byte[] buffer

private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes(

= Encoding.UTF8.GetBytes("Hello World"); e.SetBuffer(buffer, 0, buffer.Length);
Socket sock =

e.UserToken as Socket;
bool willRaiseEvent = sock.SendAsync(e);
if (!willRaiseEvent)
{
ProcessSend(e);
}

}

Слайд 30 private static void ProcessConnect(SocketAsyncEventArgs e)
{

byte[] buffer

private static void ProcessConnect(SocketAsyncEventArgs e) { 	…	byte[] buffer = Encoding.UTF8.GetBytes(

= Encoding.UTF8.GetBytes("Hello World"); e.SetBuffer(buffer, 0, buffer.Length);
Socket sock =

e.UserToken as Socket;
bool willRaiseEvent = sock.SendAsync(e);
if (!willRaiseEvent)
{
ProcessSend(e);
}

}

Слайд 31 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 32 private static void ProcessSend(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as

= e.UserToken as Socket;
bool willRaiseEvent = sock.ReceiveAsync(e);
if

(!willRaiseEvent)
{
ProcessReceive(e);
}

}

Слайд 33 private static void ProcessSend(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as

= e.UserToken as Socket;
bool willRaiseEvent = sock.ReceiveAsync(e);
if

(!willRaiseEvent)
{
ProcessReceive(e);
}

}

Слайд 34 private static void ProcessSend(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as

= e.UserToken as Socket;
bool willRaiseEvent = sock.ReceiveAsync(e);
if

(!willRaiseEvent)
{
ProcessReceive(e);
}

}

Слайд 35 private static void ProcessSend(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessSend(SocketAsyncEventArgs e) { 		…	Socket sock = e.UserToken as

= e.UserToken as Socket;
bool willRaiseEvent = sock.ReceiveAsync(e);
if

(!willRaiseEvent)
{
ProcessReceive(e);
}

}

Слайд 36 static void SocketEventArg_Completed(object sender,
SocketAsyncEventArgs e) {
switch (e.LastOperation)

static void SocketEventArg_Completed(object sender,SocketAsyncEventArgs e) { 	switch (e.LastOperation) 		{ 			case SocketAsyncOperation.Connect:


{
case SocketAsyncOperation.Connect:
ProcessConnect(e);
break;
case SocketAsyncOperation.Receive:
ProcessReceive(e);
break;
case

SocketAsyncOperation.Send:
ProcessSend(e);
break;
default: throw new Exception("Invalid operation completed"); }
}

Слайд 37 private static void ProcessReceive(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send); 	sock.Close(); 	…}

= e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send);
sock.Close();

}


Слайд 38 private static void ProcessReceive(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send); 	sock.Close(); 	…}

= e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send);
sock.Close();

}


Слайд 39 private static void ProcessReceive(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send); 	sock.Close(); 	…}

= e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send);
sock.Close();

}


Слайд 40 private static void ProcessReceive(SocketAsyncEventArgs e)
{

Socket sock

private static void ProcessReceive(SocketAsyncEventArgs e) { 	…	Socket sock = e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send); 	sock.Close(); 	…}

= e.UserToken as Socket; sock.Shutdown(SocketShutdown.Send);
sock.Close();

}


Слайд 41 Этапы выполнения асинхронной операции

Выделите  SocketAsyncEventArgs
Задайте свойства объекта SocketAsyncEventArgs,
Вызовите

Этапы выполнения асинхронной операцииВыделите  SocketAsyncEventArgsЗадайте свойства объекта SocketAsyncEventArgs, Вызовите соответствующий метод сокета.Функции

соответствующий метод сокета.
Функции обратного вызова сделайте запрос состояния завершения и

результатов операций.
Повторно используйте объект SocketAsyncEventArgs для другой операции.

  • Имя файла: sokety.pptx
  • Количество просмотров: 195
  • Количество скачиваний: 0