Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
AnswerRe: Database migration Pin
Bernhard Hiller21-Sep-10 2:11
Bernhard Hiller21-Sep-10 2:11 
GeneralRe: Database migration Pin
anishkannan21-Sep-10 2:17
anishkannan21-Sep-10 2:17 
GeneralRe: Database migration Pin
anishkannan21-Sep-10 2:17
anishkannan21-Sep-10 2:17 
QuestionCheckbox List Item Value Pin
SatyaKeerthi1520-Sep-10 23:25
SatyaKeerthi1520-Sep-10 23:25 
AnswerRe: Checkbox List Item Value Pin
Henry Minute20-Sep-10 23:30
Henry Minute20-Sep-10 23:30 
QuestionHandling mouse events in off-screen rendering Pin
HalliHaida20-Sep-10 23:04
HalliHaida20-Sep-10 23:04 
QuestionReading large data with TcpClient Pin
Chesnokov Yuriy20-Sep-10 20:47
professionalChesnokov Yuriy20-Sep-10 20:47 
AnswerRe: Reading large data with TcpClient Pin
Pete O'Hanlon20-Sep-10 22:25
mvePete O'Hanlon20-Sep-10 22:25 
Don't attempt to send such large chunks across the network. Break the stream up into smaller sizes (I find 4K blocks tend to be about right). Reading is easy with the following method:
internal static object DeserializeFromNetworkStream(IFormatter formatter, NetworkStream ns)
{
  using (MemoryStream ms = new MemoryStream())
  {
    byte[] buffer = new byte[4096];
    while (true)
    {
      int read = ns.Read(buffer, 0, buffer.Length);
      if (read > 0)
      {
        ms.Write(buffer, 0, read);
        continue;
      }
      ms.Seek(0, SeekOrigin.Begin);
      break;
    }
    return formatter.Deserialize(ms);
  }
}
Serializing the object is just as easy:
private static void SerialiseToNetworkStream<T>(NetworkStream ns, IFormatter formatter, T data)
{
    using (MemoryStream ms = new MemoryStream())
    {
        byte[] buffer;
        formatter.Serialize(ms, data);
        // Get the knowledge data.
        buffer = ms.GetBuffer();
        // Now, serialize this back over TCP
        int offset = 0;
        int size = 4096;
        int remaining = buffer.Length;
        while (remaining > 0)
        {
            if (size > remaining)
            {
                size = remaining;
            }
            ns.Write(buffer, offset, size);
            offset += size;
            remaining -= size;
        }
    }
}

I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Onyx


AnswerRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 0:30
professionalChesnokov Yuriy21-Sep-10 0:30 
GeneralRe: Reading large data with TcpClient Pin
Pete O'Hanlon21-Sep-10 1:21
mvePete O'Hanlon21-Sep-10 1:21 
AnswerMessage Closed Pin
21-Sep-10 1:05
stancrm21-Sep-10 1:05 
GeneralRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 1:37
professionalChesnokov Yuriy21-Sep-10 1:37 
GeneralRe: Reading large data with TcpClient Pin
David Knechtges21-Sep-10 3:19
David Knechtges21-Sep-10 3:19 
GeneralRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 3:51
professionalChesnokov Yuriy21-Sep-10 3:51 
GeneralRe: Reading large data with TcpClient Pin
Pete O'Hanlon21-Sep-10 4:44
mvePete O'Hanlon21-Sep-10 4:44 
QuestionRe: Reading large data with TcpClient Pin
Chesnokov Yuriy21-Sep-10 5:13
professionalChesnokov Yuriy21-Sep-10 5:13 
AnswerRe: Reading large data with TcpClient Pin
Pete O'Hanlon21-Sep-10 7:49
mvePete O'Hanlon21-Sep-10 7:49 
QuestionCorrect deserialization with BinaryFormatter Pin
Chesnokov Yuriy20-Sep-10 20:19
professionalChesnokov Yuriy20-Sep-10 20:19 
AnswerRe: Correct deserialization with BinaryFormatter Pin
Paw Jershauge21-Sep-10 0:35
Paw Jershauge21-Sep-10 0:35 
GeneralRe: Correct deserialization with BinaryFormatter Pin
Chesnokov Yuriy21-Sep-10 1:39
professionalChesnokov Yuriy21-Sep-10 1:39 
GeneralRe: Correct deserialization with BinaryFormatter Pin
Paw Jershauge21-Sep-10 2:18
Paw Jershauge21-Sep-10 2:18 
GeneralRe: Correct deserialization with BinaryFormatter Pin
Chesnokov Yuriy21-Sep-10 2:47
professionalChesnokov Yuriy21-Sep-10 2:47 
QuestionC# picture box Pin
C.CoderCreator20-Sep-10 20:05
C.CoderCreator20-Sep-10 20:05 
AnswerRe: C# picture box Pin
Pete O'Hanlon20-Sep-10 22:06
mvePete O'Hanlon20-Sep-10 22:06 
QuestionMicrosoft.Sharepoint.dll Reference. Pin
avi_dadi200220-Sep-10 20:00
avi_dadi200220-Sep-10 20:00 

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.