Binary Data Sender : Data Send Receive « Network « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Network » Data Send ReceiveScreenshots 
Binary Data Sender

using System;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

public class BinaryDataSender
{
   public static void Main()
   {
      SerialEmployee emp1 = new SerialEmployee();
      SerialEmployee emp2 = new SerialEmployee();

      emp1.EmployeeID = 1;
      emp1.LastName = "B";
      emp1.FirstName = "K";
      emp1.YearsService = 12;
      emp1.Salary = 35000.50;

      emp2.EmployeeID = 2;
      emp2.LastName = "B";
      emp2.FirstName = "J";
      emp2.YearsService = 9;
      emp2.Salary = 23700.30;

      TcpClient client = new TcpClient("127.0.0.1"9050);
      IFormatter formatter = new BinaryFormatter();
      NetworkStream strm = client.GetStream();

      formatter.Serialize(strm, emp1);
      formatter.Serialize(strm, emp2);
      strm.Close();
      client.Close();
   }
}



[Serializable]
public class SerialEmployee
{
   public int EmployeeID;
   public string LastName;
   public string FirstName;
   public int YearsService;
   public double Salary;

   public SerialEmployee()
   {
      EmployeeID = 0;
      LastName = null;
      FirstName = null;
      YearsService = 0;
      Salary = 0.0;
   }
}

           
       
Related examples in the same category
1.Better Data Receiver
2.Better Data Sender
3.Binary Data Receiver
w__ww_.j_a___v__a2_s.___co__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.