Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 18th, 2008, 05:49 AM
Authorized User
 
Join Date: Aug 2007
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to yukijocelyn
Default Help in file transfer server code

I am currently doing a file transfer project using TCP connection. However, I feel that if the file is too big for the network to handle, it will only receive the 1st packet arrived at the server and ignore the other packets waiting to be accepted. Can anyone help me and see when I have gone wrong in the codes? Thank you!


Code:
ipEnd = new IPEndPoint(IPAddress.Any, 8002);
           socketServer= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
           socketServer.Bind(ipEnd);

socketServer.Listen(100);
clientSock = socketServer.Accept();

byte[] RxData = new byte[1024 * 5000];
int receivedBytesLen = clientSock.Receive(clientData);
int fileNameLen = BitConverter.ToInt32(clientData, 0);
string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);

bWrite = new BinaryWriter(File.Open(receivedPath + "/" + fileName, FileMode.Append)); ;
bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);

bWrite.Close();
clientSock.Close();
 
Old July 18th, 2008, 06:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well you can keep calling clientSock.Receive until it returns zero.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Server.Transfer Sheraz Khan ASP.NET 2.0 Basics 1 July 28th, 2007 05:17 AM
code for downloading & uploading file in server mhadz JSP Basics 1 January 23rd, 2007 02:27 AM
Transfer data from .dbf file to SQL Server 2000 somnath.kartic SQL Server 2000 1 October 18th, 2006 11:01 AM
Transfer Data from one server to another server Jane SQL Server 2000 2 February 28th, 2005 03:15 AM
file transfer ftp server to a pocket PC in C# .NET g_hristodol ADO.NET 0 October 21st, 2004 06:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.