Prezentacja programu PowerPoint - PowerPoint PPT Presentation

About This Presentation
Title:

Prezentacja programu PowerPoint

Description:

NETWORKING tworzenie po cze sieciowych gniazda UDP, TCP klasy transportowe klasy protok w programowanie ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 26
Provided by: JanK161
Category:

less

Transcript and Presenter's Notes

Title: Prezentacja programu PowerPoint


1
NETWORKING tworzenie polaczen sieciowych       
gniazda UDP, TCP        klasy transportowe      
  klasy protokólów        programowanie
asynchroniczne
2
       gniazda UDP - odbiorca Socket listener
new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp) IPEnd
Point localEP // adres odbiorcy new
IPEndPoint(IPAddress.Any, 5001) listener.Bind(loc
alEP)
3
IPEndPoint tempRemoteEP // adres nadawcy
new IPEndPoint(IPAddress.Any,
5002) EndPoint trEP (EndPoint)tempRemoteEP
listener.Poll(-1, SelectMode.SelectRead) lis
tener.ReceiveFrom(buffer, ref trEP)
4
- nadawca string listener "localhost" Socket
client new Socket(AddressFamily.InterNet
work, SocketType.Dgram,
ProtocolType.Udp) IPEndPoint localEP // adres
nadawcy new IPEndPoint(IPAddress.Any,
5002) client.Bind(localEP)
5
buffer Encoding.ASCII.GetBytes(message) ipaddre
ss Dns.GetHostEntry(listener).Addre
ssList0 IPEndPoint remoteEP // adres
odbiorcy new IPEndPoint(ipaddress,
5001) client.SendTo(buffer, 0, buffer.Length,
SocketFlags.None, remoteEP)
UDPSocket
6
       gniazda TCP - odbiorca Socket
GetListenerSocket(string host, int port)
Socket s null, ts IPEndPoint
lep IPHostEntry iphe Dns.GetHostEntry(host)
foreach(IPAddress ipa in iphe.AddressList)
lep new IPEndPoint(ipa, port) ts new
Socket(lep.AddressFamily,
SocketType.Stream, ProtocolType.Tcp)
7
try ts.Bind(lep) ts.Listen(2) // max 2
waiting connections s ts break catch ( .
. . ) . . . return s
8
Socket server GetListenerSocket("localhost",
5010) Socket s server.Accept() byte
responseData new byte128 int
bytesRead try bytesRead s.Receive(responseDa
ta) . . . catch . . . ...
9
- nadawca Socket GetSocket(string host, int
port) Socket s null, ts IPEndPoint
ipe IPHostEntry iphe ns.GetHostEntry(host)
foreach(IPAddress ipa in iphe.AddressList)
ipe new IPEndPoint(ipa, port) ts new
Socket(ipe.AddressFamily,
SocketType.Stream, ProtocolType.Tcp)
10
try ts.Connect(ipe) s ts break
catch ( . . .) . . . return s Socket
s GetSocket("localhost", 5010) if(s
null) return s.Send(buffer)
TCPSocket
11
       klasa transportowa UDP UdpClient -
odbiorca UdpClient listener new
UdpClient(port) IPEndPoint remoteEp
new IPEndPoint(IPAddress.Any, port)   byte
buffer listener.Receive(ref remoteEp)
12
- nadawca UdpClient client new
UdpClient(port) byte buffer
Encoding.ASCII.GetBytes(message) client.Send(buf
fer, buffer.Length, listener,
port) client.Close()
UDPClass
13
       klasy transportowe TCP TcpListener
TcpClient - odbiorca TcpListener listener
new TcpListener(port) listener.Start() if
(listener.Pending()) TcpClient s
listener.AcceptTcpClient() NetworkStream
stream s.GetStream() // int bytesRead
stream.Read(responseData, 0,
responseData.Length) // byte
14
- nadawca TcpClient client new
TcpClient() client.Connect(listener,
port) NetworkStream stream client.GetStream()
stream.Write(buffer, 0, buffer.Length) // if
(stream.DataAvailable) bytesRead
stream.Read(buffer, 0, buffer.Length)
TCPClasses
15
       przesylanie z wykorzystaniem protokólu
SOAP - odbiorca NetworkStream ns
tcpclient.GetStream() SoapFormatter channel
new SoapFormatter() message (string)channel.Des
erialize(ns) - nadawca SoapFormatter
channel new SoapFormatter() channel.Serialize(t
cpclient.GetStream(), message)
TCPSOAP
16
       klasy protokólów - FTP - klasa
WebClient Uri libra new Uri (_at_"ftp//man.put.poz
nan.pl/Nowy.txt") if (libra.Scheme !
Uri.UriSchemeFtp) return WebClient request
new WebClient() request.Credentials new
NetworkCredential(name,
pass) // request.DownloadFile(libra.ToString(),
_at_"Nowy.txt")
// request.UploadFile(libra.ToString(),
_at_"Nowy.txt")
Get1
17
- klasy FtpWebRequest
FtpWebResponse Uri libra new
Uri(_at_"ftp//man.put.poznan.pl") FtpWebRequest
request (FtpWebRequest)FtpWebRequest.Create(l
ibra) request.Credentials new
NetworkCredential(name, pass) request.UseBinary
false request.Method
WebRequestMethods.Ftp.ListDirectory FtpWebRespons
e response (FtpWebResponse)request.GetRe
sponse() Stream responseStream
response.GetResponseStream()
Get2
18
       klasy protokólów - HTTP, HTTPS,
FILE - WebClient string address
_at_"http//www.cs.put.poznan.pl/jkniat/HT.html" //
_at_"https//poczta.put.poznan.pl" //
_at_"file//D/HT.html WebClient wc new
WebClient() // Console.WriteLine(Encoding.ASCII.G
etString (wc.DownloadData(add
ress))) // wc.DownloadFile(address,
"HTcopy.html")
Get1
19
- WebRequest WebResponse string address
_at_"http//www.cs.put.poznan.pl/jkniat/HT.html" We
bRequest request WebRequest.Create(address) Web
Response response request.GetResponse() Stream
Reader reader new StreamReader(response.GetRe
sponseStream(),
Encoding.ASCII) Console.WriteLine(reader.ReadToEn
d())
Get2, HTTPpage
20
       programowanie asynchroniczne - TCP
Socket Server ManualResetEvent AcceptEvent
new
ManualResetEvent(false) // ManualResetEvent
ReceiveEvent
new ManualResetEvent(false) //
synchronizacja watków za pomoca zglaszania //
zdarzen i oczekiwania na zdarzenia//
.WaitOne() .Set() .Reset()
21
void Start() Socket srv GetLisSocket
("localhost", port) AcceptEvent.Reset() ReceiveE
vent.Reset() srv.BeginAccept( new
AsyncCallback(AcceptCallback),
srv) AcceptEvent.WaitOne() // oczekiwanie na
sygnal
22
void AcceptCallback(IAsyncResult result) Socket
temp (Socket) result.AsyncState Socket a
temp.EndAccept(result) asyncData.socket a
IAsyncResult recres a.BeginReceive(ad.RecBytes,
0, 256, 0, new AsyncCallback(ReceiveCallbac
k), ad)  ReceiveEvent.WaitOne() //
oczekiwanie AcceptEvent.Set() // sygnal
dla Start
23
void ReceiveCallback(IAsyncResult
result) int bytes
ad.socket.EndReceive(result) if (bytes gt 0)
string data Encoding.ASCII.GetString(ad.Re
cBytes, 0, bytes)
Console.WriteLine("Odebrano " data
"\n")
ReceiveEvent.Set() // sygnal dla
AcceptCallback
AsyTCP
24
- HTTP string address _at_"http//www.cs.put.pozn
an.pl" WebRequest request WebRequest.Create(ad
dress) AsyncResponseData ad
new AsyncResponseData(request) IAsyncResult
responseResult
request.BeginGetResponse (new
AsyncCallback(ResponseCallback),
ad)
25
void ResponseCallback(IAsyncResult
result) AsyncResponseData ar
(AsyncResponseData)result.AsyncState
WebRequest request ar.Request WebResponse
response
request.EndGetResponse(result) Stream stream
response.GetResponseStream() AsyncReadData ad
new AsyncReadData(stream) IAsyncResult
readResult
stream.BeginRead(ad.Buffer, 0,
ad.Buffer.Length,
new AsyncCallback(ReadCallback),
ad) .
. .
AsyPage
Write a Comment
User Comments (0)
About PowerShow.com