|
m doin an applciation- file sending thru socket-
i think its send as bytes.but wht funcitoon i can use to send it.
do i need to save it to a temporary location to convert it to bytes
can any one help me
This code was posted by me...
|
|
|
|
|
send bytes in a specific format, like first of all send a long value that is the size of file and then keep send file's data in bytes...and at receiver-end first read that long value and write those bytes direct to file...
use Socket.Send() to send bytes...
Vivek Vijayan wrote: do i need to save it to a temporary location to convert it to bytes
no, .Net does itself...you can use either System.IO.File.ReadAllByte() if file size is smaller than 2GB or use FileStream
have a look at these
An Asynchronous Socket Server and Client[^]
File Transfer using Socket Application in C#.Net 2[^]
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I believe the function is called: System.IO.File.GetAllBytes()
Or something like that.
Granted, if it's a big file, you probably want to stream it a chunk at a time, using an algorithm kind of like this:
byte[] buffer = new byte[BUFFER_SIZE];
StreamReader sr = ...open the file...
while (!sr.EndOfStream)
{
int numBytes = sr.Read(buffer, 0);
yourNetworkStreamWriter.Write(buffer, 0, numBytes);
}
|
|
|
|
|
Vivek Vijayan wrote: m doin an applciation- file sending thru socket-
i think its send as bytes
Yes. It will be send as several chunks of bytes.
Vivek Vijayan wrote: wht funcitoon i can use to send it.
Your message says you are just a beginner. So try with TcpListener and TcpClient classes. However, the best way to do network programming is to work with Socket class directly.
Vivek Vijayan wrote: do i need to save it to a temporary location to convert it to bytes
File.ReadAllBytes[^] will give you bytes of a file.
I'd suggest to please avoid txtspeak[^] when you post messages. It is not readable.
|
|
|
|
|
Vivek Vijayan wrote: do i need to save it to a temporary location to convert it to bytes
Huh?! A file is already made of bytes. What conversion are you talking about?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi , have a good day
I have a DataTable with two columns
and it's rows are something like this :
<br />
--------<br />
PC1|AP1|<br />
--------<br />
AP2|AP1|<br />
--------<br />
RP1|PC4|<br />
--------<br />
AP2|PC4|<br />
--------
So , If I want to tell the path From PC1 to PC4 it would be like this :
PC1-->AP1-->AP2-->PC4
How I can tell that by Code ?
any help would be very appreciated !
even if you don't have a full answer , please just say your word.
A drowning man will clutch at a straw
Kind regards ....
I know nothing , I know nothing ...
|
|
|
|
|
You have to use a path finding algorithm. First you should define a structure which can describe your data set. The data structure for these kind of problems is usually a tree, but you should describe your problem more in detail. Are the connections one-way or two-way ?
Path finding can then be achieved by using a function to walk the data structure, starting from the source node (PC1) and visiting all of its children, and their children recursively, until the destination (PC4) node is found or you run out of children nodes.
If your connections are not one-way, then you must also flag the visited nodes in order to avoid infinite loops.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
"Padding is invalid and cannot be removed" - this is the error message I am getting when trying to decrypt a file.
I have an application which will encrypt a file and then copy the file to a network location. (No Problems)
The application can also 'download' the file and decrypt it - This is done by copying the file locally (with .tmp appended to the filename) and then decrypted to another file (so you basically end up with encrypted and decrypted files when you 'download').
If I upload a file, then I can download without problems. But I cannot download a file that another user has uploaded. Now, as I said you get two files when you download. If I use a testing application (which has exactly the same decryption code) then I can successfully decrypt the temporary file that was created during the 'download'
I cannot see the logic here at all. Please see my two methods below for encryption/decryption...
public static bool EncryptFile(string inputFile, string outputFile)
{
PasswordDeriveBytes pdb = new PasswordDeriveBytes(fileEncryptionPassword, new System.Security.Cryptography.SHA384Managed().ComputeHash(new System.Text.UnicodeEncoding().GetBytes(fileEncryptionPassword)));
byte[] key = pdb.GetBytes(32);
byte[] IV = pdb.GetBytes(16);
RijndaelManaged rm = new RijndaelManaged();
rm.Key = key;
rm.IV = IV;
rm.BlockSize = 128;
rm.Padding = PaddingMode.PKCS7;
FileStream fsIn = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
bool success = true;
try{
CryptoStream cs = new CryptoStream(fsOut, rm.CreateEncryptor(), CryptoStreamMode.Write);
int bytesToWrite = 0;
byte[] buffer = new byte[4096];
while(true)
{
bytesToWrite = fsIn.Read(buffer, 0, buffer.Length);
if(bytesToWrite == 0)
break;
cs.Write(buffer, 0, bytesToWrite);
}
cs.Close();
}
catch
{
success = false;
}
fsIn.Close();
fsOut.Close();
if(!success)
File.Delete(outputFile);
return success;
}
public static bool DecryptFile(string inputFile, string outputFile)
{
PasswordDeriveBytes pdb = new PasswordDeriveBytes(fileEncryptionPassword, new System.Security.Cryptography.SHA384Managed().ComputeHash(new System.Text.UnicodeEncoding().GetBytes(fileEncryptionPassword)));
byte[] key = pdb.GetBytes(32);
byte[] IV = pdb.GetBytes(16);
RijndaelManaged rm = new RijndaelManaged();
rm.Key = key;
rm.IV = IV;
rm.BlockSize = 128;
rm.Padding = PaddingMode.PKCS7;
FileStream fsIn = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
bool success = true;
CryptoStream cs = new CryptoStream(fsIn, rm.CreateDecryptor(), CryptoStreamMode.Read);
try{
int bytesToWrite = 0;
byte[] buffer = new byte[4096];
while(true)
{
bytesToWrite = cs.Read(buffer, 0, buffer.Length);
if(bytesToWrite == 0)
break;
fsOut.Write(buffer, 0, bytesToWrite);
}
}
catch(Exception ex)
{
Debug.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + ex.InnerException.Message);
success = false;
}
finally{
cs.Close();
}
fsIn.Close();
fsOut.Close();
if(!success)
File.Delete(outputFile);
return success;
}
Sorry for so much code, but I'm sure it will be useful.
The decryption method is called directly after the code that copies the file from the network to a local folder, this is done using File.Copy() with the overwrite property set to true.
Thanks for any help
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
This[^] may explain - make sure you read the response from Tarik Soulami [MS].
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Interesting a bug in .NET Framework.
Life is a stage and we are all actors!
|
|
|
|
|
Thanks for the reply, but I do not think this is relevant in my situation. From what I can gather the post is just saying that you need to check the return value of the Read function in order to determine how much data to write our to the file, which I am already doing.
Also, as I have said before, I can use the same code to decrypt and of the files from a test application but the main application code is only decrypting files that I have uploaded. Other users are able to decrypt their own upload in addition to other peoples, and one user can not decrypt even his own files... It just seems so random.
I also since have tried to decrypt the file straight from the network location and am still having an issue, so I can therefore rule out it being anything to do with using File.Copy to get a local copy of the file prior to decryption.
Any more suggestions?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
OK, turns out the key was being altered from else where in the code, but only in certain situations - due to some other test.
So basically an error on my part
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi all,
when the tab is changed i could get WindowStateChanged event.
and there are many tabs are there. i want to get the active tab's URL.
if i am able to identify the active tab that is enough then i can get the url.
( i have seen many posts but no ans)
can some one help me.
Regards
.....Jack
|
|
|
|
|
i have list<myclass>
myclass contains
name,sirname,age
i want to sort list first with name then sirname then age
how to so that
|
|
|
|
|
You should use IComparer interface.
Life is a stage and we are all actors!
|
|
|
|
|
Hi,
This[^] will explain what you need.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I am getting mscorlib:Authentication Failure error message when I open my application. The below piece of code executes while my application opens.
I am not understanding why this error is coming up.
private void InitializeRemoting(out int RemotingPortNumber)
{
// Establish server channel sink provider
BinaryServerFormatterSinkProvider svrSinkProvider = new BinaryServerFormatterSinkProvider();
svrSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
// Create and register tcp server channel to listen on a port.
m_serverChannel = new TcpServerChannel( "ITViewAppOperations",0,svrSinkProvider);
ChannelServices.RegisterChannel(m_serverChannel,true);
string PortNumberString = m_serverChannel.GetChannelUri().Split(':')[2];
RemotingPortNumber = Convert.ToInt32(PortNumberString);
// Register "BridgeFactory.rem" as singleton well know service types.
WellKnownServiceTypeEntry entry1 = new WellKnownServiceTypeEntry(typeof(IdeWMBridge).FullName,
typeof(IdeWMBridge).Assembly.FullName, // "AA.IDE.IdeWmBridge" "IdeWMBridge.rem",WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterWellKnownServiceType(entry1);
// Get remoting singleton bridge instance.
m_ideWmBridge = (AA.IDE.WMBridge.Common.IaaIdeWmBridge)Activator.GetObject(
typeof(AA.IDE.IdeWmBridge.IdeWMBridge),
"tcp://localhost:" + RemotingPortNumber + "/IdeWMBridge.rem");
SetLifetime(m_ideWmBridge, TimeSpan.FromDays(365 * 100));
m_ideWmBridge.IdeProxy = m_ideProxy;
}
private void SetLifetime(object obj, TimeSpan LeaseTime)
{
((ILease)((MarshalByRefObject)obj).GetLifetimeService()).Renew(LeaseTime);
}
Please let me know if anyone knows the solution.
|
|
|
|
|
Where is this exception thrown (At what line)
And put your code betwen <pre> and ;</pre>, for better view. This message looks ugly and there are people that will never try reading it.
|
|
|
|
|
no PRE tags
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
VengefulSakhmet wrote: I need to perform a query on the files located in the Registry.
There are no files located in the Registry. It contains Key and Values where a Value is actually a key-value pair.
AFAIK it does not support SQL queries because it is not a relational database.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Your database path is anything but. That's a path in the Registry, not a path to a database. You have to retrieve a value from that key (whatever name it has...), and then pass that value to the creation of the SqlConnection object.
|
|
|
|
|
Hi.
I have an asmx webservice with method which should translate sentences. There is no problem with short sentences. But with long sentencens client app must wait about 10seconds for translated sentence. How can I recognize when webmethod has finished work - on beginning I am going to show a label which informs about processing and hide it after all. Is there any simple solution of this problem?
regards
pit
|
|
|
|
|
Use the web service asynchronously, and then update the page when the method completed event is raised.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
ok. thanks a lot
|
|
|
|