Hi!
i have to upload a ms access database file to the server from my client program. The server program should connect to this database and read the data. What's the easiest way to upload the file? Is it FTP? i tried sockets, but it only allows like 9kb of data transfer capacity.
Thanks for any help
File uploading
Page 1 of 16 Replies - 510 Views - Last Post: 30 September 2012 - 07:12 PM
Replies To: File uploading
#2
Re: File uploading
Posted 29 September 2012 - 08:41 PM
How did you come to the conclusion that sockets only allows 9kb of data to be transferred?
#3
Re: File uploading
Posted 30 September 2012 - 12:40 AM
i sent a text file like 12kb to the server, but the server had received only the first 8-9kbs of the file. The file was truncated. i tried increasing the size of SendBufferSize and ReceiveBufferSize properties of the sockets both at server and client, but still the server received the same file size. i have used the typical server-client socket communication code.
#5
Re: File uploading
Posted 30 September 2012 - 07:10 AM
As mentioned in the response in the crosspost, I also think that there is something wrong with your server implementation if there is a 9KiB limit. Perforce uses sockets (I've seen the source code) to send source files back and forth and it can definitely handle more than just 9KiB, specially when some gifted individuals inadvertently check in entire binary files or databases.
#6
Re: File uploading
Posted 30 September 2012 - 05:59 PM
Thanks for the replies. Here's what my code looks like:
Server side:
Client side:
What am i doing wrong?
Server side:
private void FormServerMain_Load(object sender, EventArgs e)
{
...
Connect_SvrUpdtTransHist();
Thread_SvrUpdtTransHist = new Thread(new ThreadStart(RecieveMsg_SvrUpdtTransHist));
Thread_SvrUpdtTransHist.Start();
}
void RecieveMsg_SvrUpdtTransHist()
{
try
{
while (true)
{
// TEXT recieve
sckRecv_SvrUpdtTransHist.Listen(100);
accepted_SvrUpdtTransHist = sckRecv_SvrUpdtTransHist.Accept();
Buffer_SvrUpdtTransHist = new byte[accepted_SvrUpdtTransHist.SendBufferSize]; // buffer
int bytesRead = accepted_SvrUpdtTransHist.Receive(Buffer_SvrUpdtTransHist); // load data into buffer
byte[] formatted = new byte[bytesRead];
for (int i = 0; i < bytesRead; i++)
{
formatted[i] = Buffer_SvrUpdtTransHist[i];
}
string strData = Encoding.ASCII.GetString(formatted);
...
...
File.AppendAllText(fileused, strData);
File.AppendAllText(fileused, Environment.NewLine);
...
}
void Connect_SvrUpdtTransHist()
{
try
{
sckRecv_SvrUpdtTransHist = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sckRecv_SvrUpdtTransHist.Bind(new IPEndPoint(IPAddress.Any, 1234));
}
catch
{
MessageBox.Show("Unable to connect to remote end point");
}
}
Client side:
private void buttonUpldTransHistTxt_Click(object sender, EventArgs e)
{
...
...
ConnectSvrTransHistUpdt();
string transHistFile = "TransHist_" + comboBoxServerN.Text + ".txt";
string transHist = File.ReadAllText(transHistFile);
sck.Send(Encoding.ASCII.GetBytes(transHist));
sck.Close();
...
}
void ConnectSvrTransHistUpdt()
{
try
{
sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPOint = new IPEndPoint(IPAddress.Parse("127.0.01"), 1234);
sck.Connect(localEndPOint);
}
catch (Exception ex)
{
fa.listBoxAlarts.Items.Insert(0, ex.Message);
//MessageBox.Show(ex.Message);
}
}
What am i doing wrong?
This post has been edited by KasunL: 30 September 2012 - 06:01 PM
#7
Re: File uploading
Posted 30 September 2012 - 07:12 PM
Your use of the send buffer size to allocate the size of your receive buffer byte array looks a little suspicious.
Your server code doesn't show what conditions cause it to break out of its' while(true) loop.
Anyway, here is an example of a TCP server that will keep on taking data until it sees the text "<EOF>": http://msdn.microsof...y/6y0e13d3.aspx
Your server code doesn't show what conditions cause it to break out of its' while(true) loop.
Anyway, here is an example of a TCP server that will keep on taking data until it sees the text "<EOF>": http://msdn.microsof...y/6y0e13d3.aspx
This post has been edited by Skydiver: 30 September 2012 - 07:13 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|