How To Develop A Network Program Using Client Server Application In C#.Net
Rate this article
0 out of 5
In this tutorial we will show you how to develop a network application using client server application inC#.Net. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.


Source Code
 Class1
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

namespace Client
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try 
{
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
//Connect to the Server
tcpclnt.Connect("127.0.0.1",8001); // use the ipaddress as in the server program
Console.WriteLine("Connected");
Console.Write("Enter the string to be transmitted : ");
//Read the contents from console
String str=Console.ReadLine();
Stream stm = tcpclnt.GetStream();
//Send it to the server as ASCII Text encoding
  
ASCIIEncoding asen= new ASCIIEncoding();
byte[] ba=asen.GetBytes(str);
Console.WriteLine("Transmitting.....");
stm.Write(ba,0,ba.Length);
byte[] bb=new byte[100];
int k=stm.Read(bb,0,100);
for (int i=0;i<k;i++)
Console.Write(Convert.ToChar(bb[i]));
tcpclnt.Close();
}
catch (Exception e) 
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}
}



Source Code

About The Author
KTS Training

KTS InfoTech Training division offers various short-term programming courses for Students and Professionals who are looking for a bright career in the field of Software development.

The programming video tutorials presented in this web site are taken from some of the training sessions conducted by KTS InfoTech.

You can also learn the Programming packages through Internet directly form our English Speaking Technical experts at an affordable rate.

For more details click here and submit your training requirements.



Number Of articles Posted      : 60
Number Of Messages Posted  : 3
Joined Date : 2012/11/14
   
Author
Messages
khurram.shahzad.bs
Posted: 2014/3/27
Hi, I just started to studu socket programming in .net, just watched your this video on youtube its awesome, very interesting and very useful if you want to know the concept of socket programming and how it works, thank you so much :)
Please Login to Post Your Comments  
Name (Max 50 Chars)
Comments
 
 

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android