Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sockets Question

Posted on 2006-11-27
7
Medium Priority
?
272 Views
Last Modified: 2013-11-20
Hi guys,

We are developing a little script which transfers some files with the help of sockets, but it seems to be a bit slow...

My question is this:


Are sockets known to be slow, or is it possibly that our code has something wrong in it?

Cheers guys!
0
Comment
Question by:Cyber-Drugs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:bdunz19
ID: 18023014
My guess is your code has something wrong within. Sockets are what basically power all application connections. I wouldn't know how to connect to anything without using a socket (besides winpcap). My current project has the capability of uploading and downloading files. I used a TCP socket stream and it maxes out my bandwidth. I would post some of your recieve/send code and I'll be able to tell if you are doing something really wrong.
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18023082
Well we're only after some basic file upload/download...

I'm going to upload the project to EE-stuff.com and let you have a look at it, maybe you can point out the problems, or even provide a better solution. :)

Cheers!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18023208
Sorry, just another note...

We managed to get it to transfer quite fast, but it crashes the Server.exe


If you can't find the problem, could I maybe modify the version you had, as we're basically after moving files from computerA to computerB, nothing fancy...


Cheers!
0
 
LVL 8

Expert Comment

by:mxjijo
ID: 18023529

>> Are sockets known to be slow ?
No. sockets are fast ! :)

Its hard to say what is wrong unless you post your code, explain your network/server/local conditions.
What script do you use ? As you can assume, scripts has its own way of socket handling.
So it can be slower than a C++ application.
But, if you are doing only a simple upload/download, scripts shouldn't make a huge difference.

I would recomment you to use populat tools like FTP clients, wget etc first to see how that performs.

best
~J
0
 
LVL 4

Accepted Solution

by:
bdunz19 earned 2000 total points
ID: 18024197
Hi Cyber,

I'm just going jump into things and we'll see if this is how you are designing your file transfers!

Do you have any sort of protocol that you have implemented? If you have then create some sort of command or identifyer to alert the server that you are about to upload or download a file. Then once the server recieves that request it knows to either recv() or send() your data files.

Once the server knows what your doing, I'd implement somecode like this in your client:

// Socket creation, connection, protocol requests, ect here..
...

// Now time to start downloading/uploading:

long recvsize = 0;
char szBuf[1025] = "";

if(m_bupload) // Should we start uploading a file?
{
      FILE *pFile = NULL;
      pFile = fopen(m_filename, "rb");
      if(pFile != NULL)
      {
            int bufsize;
            ULONG filesize = 0; // Total size to reed
            ULONG cursize = 0; // Current size read
            fseek(pFile, 0, SEEK_END);
            filesize = ftell(pFile);
            fseek(pFile, 0, SEEK_SET);
            while(!feof(pFile))
            {
                  bufsize = fread(szBuf, 1, 1024, pFile);
                  cursize += bufsize;
                  if(send(sock, szBuf, bufsize, 0) == SOCKET_ERROR)
                  {
                        error = "- Error Sending Data\r\n";
                        fclose(pFile);
                        shutdown(sock, SD_SEND);
                        closesocket(sock);
                        return FALSE;
                  }
                  m_progress = (USHORT)(((float)cursize/(float)filesize)*100.0);
            }
            fclose(pFile);
            shutdown(sock, SD_SEND);
      }
}
else if(m_bdownload) // Should we start downloading a file?
{
      FILE *pFile = NULL;
      pFile = fopen(m_filename, "wb");
      if(pFile != NULL)
      {
            ULONG cursize = 0; // Current size read
            while((recvsize = recv(sock, szBuf, 1024, 0)) > 0)
            {
                  fwrite(szBuf, 1, recvsize, pFile);
                  cursize += recvsize;
                  m_progress = (USHORT)(((float)cursize/(float)m_filesize)*100.0);
            }
            fclose(pFile);
      }
      else
      {
            error = "- File Write Access Error\r\n";
            m_error = 1;
            closesocket(sock);
            return FALSE;
      }
}

shutdown(sock, SD_BOTH);
closesocket(sock);

Now once you have an idea of what the client should be doing, you can simply reverse the order for the server. So when the client is performing a recv() the server better be doing the oposite with a send().

As you can see, the data is written as it is being recieved or sent as it is being read. I was wondering if youmight have been performing somthing other than that and would cause low performance...

Anyway, let me know if you have any questions!

Good luck,
Brandon
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 18029536
We managed to create a work-around for what we were after, but thanks for sharing that bit of code, it most likely will come in handy for something else in the near future, cheers!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question