الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

serialization over network

مغلق
بدأه Csharpo في 6 يوليو 2006 · 0 رد · 516 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1

I have problem with C# .Net and I think you can help.

I make socket programming between client-server. I want to serialize

objects and send them from the server to client.

Any time I make this, exception happens when the sender deserialize

the object. that has been sent by the server

//struct to be serialized

[serializable()]

public struct port_data : ISerializable

{

//public int PortNo;

public string ProcessName;

// public int ProcessId;

//public string StrState;

//DeSerialization constructor

public port_data(SerializationInfo info, StreamingContext context)

{

//PortNo = (int)info.GetValue("PortNumber", typeof(int));

ProcessName = (string)info.GetValue("Processnm", typeof(string));

//ProcessId = (int)info.GetValue("PID", typeof(int));

//StrState = (string)info.GetValue("State", typeof(string));

}

///server code

port_data wmidata = new port_data ();

Stream stream = File.Open("EmployeeInfo.osl", FileMode.Create);

BinaryFormatter bformatter = new BinaryFormatter();

bformatter.Serialize(stream, wmidata);

stream.Close();

/////

FileInfo finf = new FileInfo("EmployeeInfo.osl");

FileStream fs2 = new FileStream("EmployeeInfo.osl", FileMode.Open, FileAccess.Read);

byte[] fileInBytes = new byte[finf.Length];

fs2.Read(fileInBytes, 0, (int)finf.Length);

fs2.Close(); fs2 = null;

m_clientSocket.Send(fileInBytes);

StopSocketListener();

///client code

Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

clientSocket.Connect(new IPEndPoint(IPAddress.Parse(ipaddress), 5300));

clientSocket.Send(Encoding.ASCII.GetBytes("start" + "\r\n"));

byte[] data = new byte[RcvdDataSize];// 10 KB

clientSocket.Receive(data);

FileStream filestream = new FileStream("NewInfo.osl", FileMode.Create, FileAccess.ReadWrite);

filestream.Write(data, 0, (int)data.Length);

filestream.Close(); filestream = null;

//Open the file written above and read values from it.

Stream stream = File.Open("NewInfo.osl", FileMode.Open);

BinaryFormatter bformatter = new BinaryFormatter();

port_data dd = (port_data)bformatter.Deserialize(stream);

stream.Close();

clientSocket.Close();

i have an exception at the red line,,obejct couldn't be deserialized :blink:

exception ::::

Unable to find assembly 'TCPService, Version=1.0.2380.9382, Culture=neutral, PublicKeyToken=null'.

where TCPService is the name of the server program

تم تعديل هذه المشاركة بواسطة Csharpo في 6 يوليو 2006 في 06:58

هذا الموضوع مغلق.

مواضيع مشابهة