najila
Uploaded by
12 SLIDES
310 VUES
130LIKES

Socket Programming Laboratory: Overview of TCP Client and Server Implementation

DESCRIPTION

This overview introduces key classes in socket programming, focusing on the TcpListener and TcpClient classes for creating TCP servers and clients. It explains how to listen for and accept incoming connections in blocking synchronous mode and the data transmission methods available in the NetworkStream class. Examples include EchoServerTCP and EchoClientTCP, with exercises to enhance functionality through word conversion and chat programs. Additionally, the guide covers file transfer implementations, showcasing the versatility of socket programming.

1 / 12

Télécharger la présentation

Socket Programming Laboratory: Overview of TCP Client and Server Implementation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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

More Related