Socket Program>?????
-
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;} =====================================================================
-
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;} =====================================================================
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-----