Click here to Skip to main content
15,925,113 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with peer to peer communication Pin
Eric Gunnerson (msft)28-May-02 9:05
Eric Gunnerson (msft)28-May-02 9:05 
GeneralFile I/O In C# Pin
Nick Parker26-May-02 5:10
protectorNick Parker26-May-02 5:10 
GeneralRe: File I/O In C# Pin
James T. Johnson26-May-02 5:31
James T. Johnson26-May-02 5:31 
GeneralRe: File I/O In C# Pin
Nick Parker26-May-02 5:39
protectorNick Parker26-May-02 5:39 
GeneralMessenger API & C# Pin
Rocky Moore25-May-02 6:22
Rocky Moore25-May-02 6:22 
GeneralRe: Messenger API & C# Pin
Nish Nishant25-May-02 6:57
sitebuilderNish Nishant25-May-02 6:57 
GeneralRe: Messenger API & C# Pin
Rocky Moore25-May-02 12:41
Rocky Moore25-May-02 12:41 
GeneralRe: Messenger API & C# Pin
Nish Nishant25-May-02 15:33
sitebuilderNish Nishant25-May-02 15:33 
GeneralRe: Messenger API & C# Pin
SimonS25-May-02 10:25
SimonS25-May-02 10:25 
GeneralConsole in Windows Pin
24-May-02 13:46
suss24-May-02 13:46 
GeneralRe: Console in Windows Pin
zhoujun24-May-02 15:27
zhoujun24-May-02 15:27 
GeneralRe: Console in Windows Pin
Nish Nishant25-May-02 4:07
sitebuilderNish Nishant25-May-02 4:07 
GeneralRe: Console in Windows Pin
James T. Johnson25-May-02 4:18
James T. Johnson25-May-02 4:18 
GeneralRe: Console in Windows Pin
Nish Nishant25-May-02 6:58
sitebuilderNish Nishant25-May-02 6:58 
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 

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.