Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Socket Program>?????

Socket Program>?????

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    h_wing
    wrote on last edited by
    #1

    i'm make Socket program this is Receive file this img file, avi file.. but can't Receive XMLfiles this is source * Receive File info ================================================================ while(rData!=null) { byte[] rbuffer = new Byte[1024]; int rcount = rData.Receive(rbuffer, rbuffer.Length, 0); string Cm = ed.GetString(rbuffer); Cm = Cm.Substring(0, rcount); Cml = null; Cml = Cm.Split(':'); this.listBox1.Items.Add("Header Info"); this.listBox1.Items.Add("Data Type : " + Cml[0]); this.listBox1.Items.Add("Data Name : " + Cml[1]); this.listBox1.Items.Add("Data Length : " + Cml[2]); if (Cml[0] == "Binnary") { FileReceive(rData, Cml);} else if (Cml[0] == "Str") {this.listBox1.Items.Add("String Value :" + Cml[3]);} rData.Close(); rData = null;} =================================================================== * Receive file ================================================================ FileStream fout = new FileStream(@"c:\youngTemp\" + cml[1]+"1",FileMode.Create, FileAccess.Write); NetworkStream nfs = new NetworkStream(rData); long DataSize = int.Parse(cml[2]); long rby = 0; try { while(rby < DataSize) { byte[] buffer = new Byte[1024]; int i = nfs.Read(buffer, 0, buffer.Length); fout.Write(buffer, 0, i); rby += 1; } this.listBox1.Items.Add("Success ");}catch(Exception ex) { this.listBox1.Items.Add("Error"); this.listBox1.Items.Add("Error is : " + ex.ToString());} finally{ fout.Close();nfs.Close(); nfs= null;fout = null;} =====================================================================

    H 1 Reply Last reply
    0
    • H h_wing

      i'm make Socket program this is Receive file this img file, avi file.. but can't Receive XMLfiles this is source * Receive File info ================================================================ while(rData!=null) { byte[] rbuffer = new Byte[1024]; int rcount = rData.Receive(rbuffer, rbuffer.Length, 0); string Cm = ed.GetString(rbuffer); Cm = Cm.Substring(0, rcount); Cml = null; Cml = Cm.Split(':'); this.listBox1.Items.Add("Header Info"); this.listBox1.Items.Add("Data Type : " + Cml[0]); this.listBox1.Items.Add("Data Name : " + Cml[1]); this.listBox1.Items.Add("Data Length : " + Cml[2]); if (Cml[0] == "Binnary") { FileReceive(rData, Cml);} else if (Cml[0] == "Str") {this.listBox1.Items.Add("String Value :" + Cml[3]);} rData.Close(); rData = null;} =================================================================== * Receive file ================================================================ FileStream fout = new FileStream(@"c:\youngTemp\" + cml[1]+"1",FileMode.Create, FileAccess.Write); NetworkStream nfs = new NetworkStream(rData); long DataSize = int.Parse(cml[2]); long rby = 0; try { while(rby < DataSize) { byte[] buffer = new Byte[1024]; int i = nfs.Read(buffer, 0, buffer.Length); fout.Write(buffer, 0, i); rby += 1; } this.listBox1.Items.Add("Success ");}catch(Exception ex) { this.listBox1.Items.Add("Error"); this.listBox1.Items.Add("Error is : " + ex.ToString());} finally{ fout.Close();nfs.Close(); nfs= null;fout = null;} =====================================================================

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      You should debug your code. An XML file is no different than a image file or an AVI - they are all just a stream of bytes. If your app treats them as such (And your code indicates that you do), then your app doesn't care - at the time of transfer - what is in the files themselves. XML files are not these special files sent from God, but just a formatted document, formatted accordingly to certain "guidelines" just like the various image codecs and AVI codecs. The only problem I can see if your code is that you're writing out a binary file. Depending on how bytes are written or transfered, you may need to take file encodings into account. The only difference between the XML files you mention and the image and AVI files is that the former is a text file (ASCII, UTF8, Unicode, etc.) while the latter two are binary. There many be a problem in the way you handle text files. You should consider what FTP does, which is send such files using a text encoding while transfering.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups