Download
socket programming n.
Skip this Video
Loading SlideShow in 5 Seconds..
Socket Programming PowerPoint Presentation
Download Presentation
Socket Programming

Socket Programming

67 Vues Download Presentation
Télécharger la présentation

Socket Programming

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Socket Programming Laboratory - 4

  2. Overview • TcpListenerClass • Provides simple methods that listen for and accept incoming connection requests in blocking synchronous mode. You can use either a TcpClient or a Socket to connect with aTcpListener. • TCPClientClass • Provides client connections for TCP network services. • NetworkStreamClass • Provides methods for sending and receiving data over Stream sockets in blocking mode.

  3. TCP Server • Example : EchoServerTCP.cs • TcpListener class constructor public TcpListener(int) public TcpListener(IPEndPoint) public TcpListener(IPAddress, int) • Start listening for connection public void Start() public void Start(int) • Accept incoming connection public TcpClientAcceptTcpClient() • Stop listener public void Stop()

  4. TCP Client • Example : EchoClientTCP.cs • TcpClient class constructor public TcpClient() public TcpClient(AddressFamily) public TcpClient(IPEndPoint) public TcpClient(string, int) • Data transfer using NetworkStream class public NetworkStreamGetStream() • Receive Data public override int Read(byte[], int, int) • Send Data public override void Write(byte[], int, int)

  5. Example 1 • EchoServerTCP.cs and EchoClientTCP.cs

  6. Exercise 1 • Modify the EchoServerTCP.cs program that the server will reply by capitalising each word, and convert the remaining letters to lower case as shown below: • Input> all in lowercase • Reply> All In Lowercase • Input> mIxEDdaTACaSeS • Reply> Mixed Data Cases

  7. Data Encoding • Example : CharEncoding.cs • GetBytes(), GetString() method • Message is sent over the network 1 byte at a time • Encoding technique • ASCII • Unicode

  8. Example 2 • Uppercase Conversion Program • UppercaseServer.cs, UppercaseClient.cs

  9. Exercise 2 • Instead of using only TcpListener class and TcpClient class, change the upper case conversion program using only Socket Class implementation.

  10. Example 3 • Simple Chat Program • ChatServer.cs, ChatClient.cs

  11. Exercise 3 • Modify the ChatServer.cs program using only Socket Class implementation instead of using TcpListenerclass and TcpClient class

  12. Example 4 • File Transfer Program • FileServer.cs, FileClient.cs