473,378 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Socket.SendFile( ) alt. in .net 1.1?

Hi all,
I'm using .NET 2.0 but unfortunately there's a windows service that
needs to be implemented in .NET 1.1 ... so I need to send a file to a
server, what's the similar method of doing so in 1.1?

Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);

client.Connect("127.0.0.1", 8000);

string fileName = "C:\\Folder\\file.xml";

client.SendFile(fileName);
client.Shutdown(SocketShutdown.Both);
client.Close();
TIA

Sep 25 '06 #1
1 4264
Well after some time on MSDN & books I managed to get this & add it to
my code (not tested yet) ... comments are welcome.

{
Int32 port = 8000;
private static string fileToUpload;
// get the file path from a config file (xml)
fileToUpload =
ConfigurationSettings.AppSettings.Get("CSV").ToStr ing();

Stream fileStream = File.OpenRead(fileToUpload);
// Alocate memory space for the file
byte[] fileBuffer = new byte[fileStream.Length];
fileStream.Read(fileBuffer, 0, (int)fileStream.Length);
// Open a TCP/IP Connection and send the data
TcpClient clientSocket=new TcpClient("127.0.0.1", port);
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Write(fileBuffer,0,fileBuffer.GetLen gth(0));
networkStream.Close();
}
Aerodyne wrote:
Hi all,
I'm using .NET 2.0 but unfortunately there's a windows service that
needs to be implemented in .NET 1.1 ... so I need to send a file to a
server, what's the similar method of doing so in 1.1?

Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);

client.Connect("127.0.0.1", 8000);

string fileName = "C:\\Folder\\file.xml";

client.SendFile(fileName);
client.Shutdown(SocketShutdown.Both);
client.Close();
TIA
Sep 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
0
by: Fil | last post by:
This is a similar problem to what I am having. Where is the code though? Fil >-----Original Message----- >Hye friends, > I am Jigar Mehta from India. Currently I am developing an...
1
by: djc | last post by:
the system.net.sockets.socket class has the 'sendfile' method. What do you do on the other end to 'receive' the file? I know the regular socket.receive will receive the data into a buffer (a byte...
0
by: Simon Says | last post by:
Hi all, Can anyone advice on how to use the SendFile function? If I have a connection-oriented socket, I'll do a sck.SendFile("C:\test.txt") to send out the file, but what should I do on...
0
by: iwdu15 | last post by:
hi, using sockets, how can i receive a file? i see a SendFile method, but no receivefile? ive done simple text sending and bytes, but that requires knowing an array size...so how can i receive a...
0
by: iwdu15 | last post by:
hi, ive done work with sockets and such before, so its nothing new. thought id try the Socket.SendFile() method instead of the manual way. however, there is no Socket.ReceiveFile() method. How do...
0
by: Matt | last post by:
Hi all, Probably a silly mistake, but I seem to be losing 24 bytes every time I attempt to send a file using Socket.SendFile(). Here is my code: Here is the server method: void...
4
by: Greg Copeland | last post by:
I'm having a brain cramp right now. I can't see to recall the name of a module. I know there is a python module which allows for optimized socket writes on Linux. It uses a syscall to obtain its...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.