Click here to Skip to main content
15,918,485 members
Home / Discussions / C#
   

C#

 
GeneralRe: Console in Windows Pin
Phil Bolduc27-May-02 13:51
Phil Bolduc27-May-02 13:51 
GeneralPreProcessMessage Pin
24-May-02 4:30
suss24-May-02 4:30 
GeneralRe: PreProcessMessage Pin
Joshua Nussbaum24-May-02 6:27
Joshua Nussbaum24-May-02 6:27 
GeneralCrystal Reports Not Working Pin
Gavin_Mannion24-May-02 3:55
Gavin_Mannion24-May-02 3:55 
GeneralMDIChild Activated() event not firing...... Pin
Pranoti24-May-02 1:45
Pranoti24-May-02 1:45 
GeneralRe: MDIChild Activated() event not firing...... Pin
Rocky Moore24-May-02 19:17
Rocky Moore24-May-02 19:17 
GeneralSockets/Objects/Serializable Pin
Paddy24-May-02 1:30
Paddy24-May-02 1:30 
GeneralRe: Sockets/Objects/Serializable Pin
James T. Johnson24-May-02 7:54
James T. Johnson24-May-02 7:54 
public byte[] GetObjectBytes(object o)
{
  MemoryStream memstream = new MemoryStream();
  IFormatter formatter = new BinaryFormatter();
 
  formatter.Serialize(memstream, o);
 
  memstream.Close(); // Prevent further writing
 
  return memstream.GetBuffer();
}
 
public object GetObjectFromBytes(byte [] bytes)
{
  MemoryStream memstream = new MemoryStream(bytes);
  IFormatter formatter = new BinaryFormatter();
 
  object o = formatter.Deserialize(memstream);
 
  memstream.Close();
 
  return o;
}


I'm not a network guy, but I assume you just call the Write method on the NetworkStream object representing your socket, to send the byte array, then call the Read method on the other side to read back the byte array.

GetObjectBytes() will serialize the object and return the byte array which you can pass to Write, GetObjectFromBytes() will deserialize the byte array from the Read method.

HTH,

James

Simplicity Rules!
GeneralRe: Sockets/Objects/Serializable Pin
tmagoo24-May-02 19:39
tmagoo24-May-02 19:39 
GeneralRe: Sockets/Objects/Serializable Pin
James T. Johnson25-May-02 4:17
James T. Johnson25-May-02 4:17 
GeneralRe: Sockets/Objects/Serializable Pin
Paddy25-May-02 4:39
Paddy25-May-02 4:39 
GeneralRe: Sockets/Objects/Serializable Pin
tmagoo26-May-02 3:35
tmagoo26-May-02 3:35 
GeneralRe: Sockets/Objects/Serializable Pin
Paddy27-May-02 2:37
Paddy27-May-02 2:37 
GeneralRe: Sockets/Objects/Serializable Pin
tmagoo29-May-02 10:59
tmagoo29-May-02 10:59 
GeneralRe: Sockets/Objects/Serializable Pin
James T. Johnson29-May-02 18:02
James T. Johnson29-May-02 18:02 
GeneralRe: Sockets/Objects/Serializable Pin
tmagoo30-May-02 3:14
tmagoo30-May-02 3:14 
GeneralPlatform Interop - Structures and Arrays Pin
Mikko Puonti24-May-02 0:09
Mikko Puonti24-May-02 0:09 
GeneralXmlDocument with DTD driving me insane! Pin
Daniel Turini23-May-02 10:21
Daniel Turini23-May-02 10:21 
QuestionWindows services???? Pin
Rickard Andersson2023-May-02 4:37
Rickard Andersson2023-May-02 4:37 
AnswerRe: Windows services???? Pin
Nish Nishant23-May-02 17:06
sitebuilderNish Nishant23-May-02 17:06 
GeneralRe: Windows services???? Pin
Rickard Andersson2023-May-02 20:48
Rickard Andersson2023-May-02 20:48 
GeneralRe: Windows services???? Pin
Nish Nishant23-May-02 20:52
sitebuilderNish Nishant23-May-02 20:52 
GeneralRe: Windows services???? Pin
Rickard Andersson2023-May-02 21:20
Rickard Andersson2023-May-02 21:20 
GeneralRe: Windows services???? Pin
Nish Nishant23-May-02 21:20
sitebuilderNish Nishant23-May-02 21:20 
GeneralRe: Windows services???? Pin
Rickard Andersson2023-May-02 22:17
Rickard Andersson2023-May-02 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.