Click here to Skip to main content
16,004,887 members
Home / Discussions / C#
   

C#

 
QuestionGetting size of a data structure Pin
LighthouseJ4-Mar-06 17:33
LighthouseJ4-Mar-06 17:33 
AnswerRe: Getting size of a data structure Pin
Expert Coming4-Mar-06 18:17
Expert Coming4-Mar-06 18:17 
GeneralRe: Getting size of a data structure Pin
LighthouseJ5-Mar-06 3:57
LighthouseJ5-Mar-06 3:57 
AnswerRe: Getting size of a data structure Pin
S. Senthil Kumar4-Mar-06 19:02
S. Senthil Kumar4-Mar-06 19:02 
GeneralRe: Getting size of a data structure Pin
LighthouseJ5-Mar-06 4:02
LighthouseJ5-Mar-06 4:02 
GeneralRe: Getting size of a data structure Pin
S. Senthil Kumar5-Mar-06 8:12
S. Senthil Kumar5-Mar-06 8:12 
GeneralRe: Getting size of a data structure Pin
LighthouseJ5-Mar-06 8:19
LighthouseJ5-Mar-06 8:19 
QuestionFile Transfer Pin
unrealed4-Mar-06 14:30
unrealed4-Mar-06 14:30 
Hello everybody, I tryed to make a software that check for updates:

Client: Login ( username , password ) , Receive update list , request updating files , get files , execute another process.

Server: Receive login , login on data-base if possible , send update list if logged , send requested files , logout.

Everythings are done, if I run CLIENT and SERVER on local computer, everythings works fine, but if I run SERVER on my computer, and CLIENT in another computer, the UPDATE doesnt work fine.

What happens:
Server can send any Text file good, in perfect state, but if I send binary files like JPG images, EXE, or any other things that arent TEXT FILES, it sends wrong BYTES, like if server is encoding all bytes to TEXT format...

===

CLIENT GET FILE VOID:

<br />
<br />
//Private Void:<br />
private void GetFile ( int FileNumber )<br />
{<br />
	string FilePath = UpdateFileList[FileNumber];<br />
	long FileSize = UpdateSizeList[FileNumber];<br />
<br />
	long CurrentSize = 0;<br />
<br />
	if ( FilePath.IndexOf("\\") > 0 )<br />
	{<br />
		string newDirectory = FilePath.Substring(0,FilePath.IndexOf("\\"));<br />
<br />
		if ( !Directory.Exists(newDirectory) )<br />
		 Directory.CreateDirectory(newDirectory);<br />
	}<br />
<br />
	FileStream FS = new FileStream(FilePath,FileMode.Create,FileAccess.Write);<br />
<br />
	while ( CurrentSize < FileSize )<br />
	{<br />
		try<br />
		{<br />
			this.Stats_Text.Text = "Downloading updatings ( " + (FileNumber+1) + " / " + UpdateFileList.Length + " )\n" + FilePath + " ( " + Convert.ToByte((Convert.ToDouble(CurrentSize)/Convert.ToDouble(FileSize))*100) + " % completed of " + (FileSize/1024) + " KBs )";<br />
			long PacketSize = FileSize-CurrentSize;<br />
<br />
			if ( PacketSize > 128 )<br />
			 PacketSize = 128;<br />
					<br />
			byte[] Packet = new byte[PacketSize];<br />
<br />
			NS.Read(Packet,0,Packet.Length);<br />
			NS.Flush();<br />
<br />
			FS.Write(Packet,0,Packet.Length);<br />
			FS.Flush();<br />
<br />
			CurrentSize += PacketSize;<br />
			FS.Seek(CurrentSize,SeekOrigin.Begin);<br />
		}<br />
<br />
		catch<br />
		{<br />
			try { File.Delete(FilePath); }<br />
			catch {}<br />
<br />
			this.Stats_Text.Text = "The connection with the Server was lost";<br />
			Disconnect();<br />
		}<br />
	}<br />
<br />
	FS.Close();<br />
}<br />
<br />


===

SERVER SEND FILE VOID:

<br />
<br />
//Private Void:<br />
private void SendFile ( int FileNumber )<br />
{<br />
	Console.Write("US - Sending updating file : " + (FileNumber+1) + " / " + Owner.UpdateFileList.Length + " [ " + ClientUserName + " ]\n");<br />
<br />
	string FilePath = Owner.UpdateFileList[FileNumber];<br />
	long FileSize = Owner.UpdateSizeList[FileNumber];<br />
<br />
	long CurrentSize = 0;<br />
<br />
	FileStream FS = new FileStream(FilePath,FileMode.Open,FileAccess.Read);<br />
	BinaryReader BR = new BinaryReader(FS);<br />
<br />
	while ( CurrentSize < FileSize )<br />
	{<br />
		try<br />
		{<br />
			long PacketSize = FileSize-CurrentSize;<br />
<br />
			if ( PacketSize > 128 )<br />
			 PacketSize = 128;<br />
<br />
			byte[] Packet = new byte[PacketSize];<br />
			Packet = BR.ReadBytes(Convert.ToInt32(PacketSize));<br />
<br />
			NS.Write(Packet,0,Packet.Length);<br />
			NS.Flush();<br />
<br />
			CurrentSize += PacketSize;<br />
		}<br />
<br />
		catch<br />
		{<br />
			Disconnect();<br />
		}<br />
	}<br />
<br />
	BR.Close();<br />
	FS.Close();<br />
}<br />
<br />


===

Can someone help me plz? whats wrong on my code.
Thank you!
GeneralRe: File Transfer Pin
LighthouseJ4-Mar-06 17:16
LighthouseJ4-Mar-06 17:16 
GeneralRe: File Transfer Pin
unrealed5-Mar-06 4:14
unrealed5-Mar-06 4:14 
GeneralRe: File Transfer Pin
unrealed5-Mar-06 5:31
unrealed5-Mar-06 5:31 
GeneralRe: File Transfer Pin
LighthouseJ5-Mar-06 5:52
LighthouseJ5-Mar-06 5:52 
GeneralRe: File Transfer Pin
unrealed5-Mar-06 10:33
unrealed5-Mar-06 10:33 
Questionimporting DLL from SQL, Possible ? Pin
emran8344-Mar-06 13:39
emran8344-Mar-06 13:39 
AnswerRe: importing DLL from SQL, Possible ? Pin
Stanciu Vlad4-Mar-06 21:52
Stanciu Vlad4-Mar-06 21:52 
QuestionHow to interact with a SysTreeView in another application? Pin
luddet4-Mar-06 13:06
luddet4-Mar-06 13:06 
Questionscroll an image Pin
Susuko4-Mar-06 12:31
Susuko4-Mar-06 12:31 
AnswerRe: scroll an image Pin
AFSEKI5-Mar-06 5:01
AFSEKI5-Mar-06 5:01 
QuestionProcess List Pin
Sean894-Mar-06 12:15
Sean894-Mar-06 12:15 
AnswerRe: Process List Pin
Thomas Stockwell4-Mar-06 17:21
professionalThomas Stockwell4-Mar-06 17:21 
QuestionFrom listBox to textBox Pin
CodeItWell4-Mar-06 11:39
CodeItWell4-Mar-06 11:39 
AnswerRe: From listBox to textBox Pin
Paul Conrad4-Mar-06 12:36
professionalPaul Conrad4-Mar-06 12:36 
GeneralRe: From listBox to textBox Pin
Paul Conrad4-Mar-06 12:46
professionalPaul Conrad4-Mar-06 12:46 
QuestionDesign Time Events? Pin
cnich234-Mar-06 7:48
cnich234-Mar-06 7:48 
AnswerRe: Design Time Events? Pin
Thomas Stockwell4-Mar-06 17:16
professionalThomas Stockwell4-Mar-06 17:16 

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.