6 Replies - 1889 Views - Last Post: 30 September 2012 - 07:12 PM Rate Topic: -----

#1 KasunL  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 11-April 11

File uploading

Posted 29 September 2012 - 08:36 PM

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
Is This A Good Question/Topic? 0
  • +

Replies To: File uploading

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3590
  • View blog
  • Posts: 11,166
  • Joined: 05-May 12

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?
Was This Post Helpful? 0
  • +
  • -

#3 KasunL  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 11-April 11

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.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: File uploading

Posted 30 September 2012 - 06:23 AM

Crosspost
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3590
  • View blog
  • Posts: 11,166
  • Joined: 05-May 12

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.
Was This Post Helpful? 0
  • +
  • -

#6 KasunL  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 59
  • Joined: 11-April 11

Re: File uploading

Posted 30 September 2012 - 05:59 PM

Thanks for the replies. Here's what my code looks like:

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

Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3590
  • View blog
  • Posts: 11,166
  • Joined: 05-May 12

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

This post has been edited by Skydiver: 30 September 2012 - 07:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1