11 Replies - 484 Views - Last Post: 01 December 2013 - 04:49 PM Rate Topic: -----

#1 vpdic  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 82
  • Joined: 24-November 13

Multiple sockets and threading woes.

Posted 30 November 2013 - 05:58 PM

I'm working on a proxy scanner as it will accomplish a lot of task I want to overcome during my entry to the C# language. I understand the many problems that can become from threading as well the benefits; however, when it comes to sockets I'm not sure which route to go.

Being a proxy scanner I am expecting to run about 200 sockets at any given time with a reset time of about 7 seconds per socket. I know I can accomplish this using asynchronous sockets, but I feel like this would create a lot of overhead with heavy use. I'm looking for guidance on what would be the best technique to utilize for a very demanding socket environment such as this, and a brief explanation as to why please.

Low processor and RAM usage is important, and accuracy of course is a must.

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple sockets and threading woes.

#2 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 801
  • View blog
  • Posts: 3,501
  • Joined: 03-December 12

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 06:04 PM

Only you can decide what best meets what your requirements are. Research the technologies and did. This is where planning and research comes in, on your part. If you specific questions on a technology then ask, but don't expect this board to do the research when we don't know what your specific requirements are or what your usage will be.
Was This Post Helpful? 0
  • +
  • -

#3 vpdic  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 82
  • Joined: 24-November 13

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 07:51 PM

I stated the requirements and usage. I did lots of research but nothing seems to really cover what I asked. Was hoping someone with experience in this area may know.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,481
  • Joined: 05-May 12

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 08:25 PM

What's the point of need the low processor and RAM usage, as well as your speed requirements of handling 200 sockets at a time? If you are doing this as a white hat, then you only need to scan once and it takes however long it will take to scan. If on the other hand, you are doing the scan as a black hat, then I can see the required speed and low system impact since you want to stay under the radar.
Was This Post Helpful? 0
  • +
  • -

#5 vpdic  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 82
  • Joined: 24-November 13

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 08:29 PM

I could just as much be making a web browser, or a chat client. I'm trying to keep resource usage low because no one wants a program to eat up their resources, and it makes for good practice. I don't understand why my agenda should affect how a program runs?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,481
  • Joined: 05-May 12

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 08:35 PM

To this forum, agenda matters. We don't help people create malware, keyloggers, cracking tools, etc.

With a web browser or chat client, you are limited by the speed at which the user can start up new browsing sessions or chat sessions. Your proxy scanner has different usage characteristics.
Was This Post Helpful? 1
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5677
  • View blog
  • Posts: 12,208
  • Joined: 02-June 10

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 08:44 PM

Boiling down you're question you're really saying... "Can someone design my solution for me because I've done some googling but can't find a step-by-step tutorial I can plagiarize.."

The reality is... We will help you learn coding. We will answer specific questions with a specific issue - ABOUT CODE. But we aren't a free software architecture and design service. We aren't going to rack up 500 hours designing your application, then another 50 writing the explanation for you. So you can then just do the code monkey part of it.

You might consider that if you can't draft of the first version of your application's design, then you aren't ready to build it yet. Its really just that simple. The first version won't be perfect. You'll learn so much by making it that revision 2 will be pretty cool, and revision 3 might be releasable at public version 1. Then it will keep getting better from there. But if you can't come up with the design for in-house beta 1, then you need to keep working on smaller projects and work your way up the ladder to this one.
Was This Post Helpful? 0
  • +
  • -

#8 vpdic  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 82
  • Joined: 24-November 13

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 09:46 PM

View PosttlhIn`toq, on 30 November 2013 - 08:44 PM, said:

Boiling down you're question you're really saying... "Can someone design my solution for me because I've done some googling but can't find a step-by-step tutorial I can plagiarize.."

The reality is... We will help you learn coding. We will answer specific questions with a specific issue - ABOUT CODE. But we aren't a free software architecture and design service. We aren't going to rack up 500 hours designing your application, then another 50 writing the explanation for you. So you can then just do the code monkey part of it.

You might consider that if you can't draft of the first version of your application's design, then you aren't ready to build it yet. Its really just that simple. The first version won't be perfect. You'll learn so much by making it that revision 2 will be pretty cool, and revision 3 might be releasable at public version 1. Then it will keep getting better from there. But if you can't come up with the design for in-house beta 1, then you need to keep working on smaller projects and work your way up the ladder to this one.


I'm not sure any of you have read any of my post. I have no intents of running the program other than to determine that it works. It has many challenges I would like to over-come, and a variety of techniques I will likely use in the future to some degree. It's not meant to harm anyone or be used for anything 'black hat.' I'm not asking for anyone to write code, did I ever ask for code, no I did not.

I'm asking for an opinion as to what would be the best route to achieve what I described in my first post. In case that was overlooked, which seemingly was, I will once again repeat myself. I am trying to understand which method would be best to handle simultaneous socket connections with very low overhead. I'm looking for technique suggestions, and I'll do my own research from there.

If you don't have anything constructive to say then you have no need to reply. Thank you.

A simple, check out this class or that class would more than suffice. I don't know all of the ins and outs of this language yet so some features may be unknown to me currently.
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,481
  • Joined: 05-May 12

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 10:55 PM

View Postvpdic, on 30 November 2013 - 07:58 PM, said:

I know I can accomplish this using asynchronous sockets, but I feel like this would create a lot of overhead with heavy use.


Is this just a feeling, or do you have profiling numbers to back it up?

If you crack open any edition of the "Inside NT" books, you'll discover that NT actually operates on asynchronous I/O at its core and that the synchronous APIs are there for convenience. If you stop and think about it makes sense. You don't want your OS stuck waiting for data to be transferred from the disk/wire/memory etc. You want the OS to be constantly servicing some other request while it waits for a potentially long operation.
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,500
  • Joined: 29-May 08

Re: Multiple sockets and threading woes.

Posted 30 November 2013 - 11:43 PM

A Thread has an 1 megabyte of memory cost that can't be eliminated. It soon adds up.
Then factor in the cpu can only support a finite number of threads in parallel. eg 2 Cores with 2 hyperthreads. The cost context switching then has to be factored in.

Where as Tasks are lightweight (in terms of memory) and multiple tasks can work one single thread. VS2012 made asynchronous design a lot easier to write, thanks to async and await.
Was This Post Helpful? 1
  • +
  • -

#11 vpdic  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 82
  • Joined: 24-November 13

Re: Multiple sockets and threading woes.

Posted 01 December 2013 - 02:27 PM

Skydiver, I previously was learning vb.net but became distracted and took a break. While learning I was working on a multi-socket chat program and had noticed that RAM use went up more than expected when connecting multiple sockets. This was just on a small scale, so I suspected it would be far more burdening on something more demanding such as a proxy scanner.

AdamSpeight2008: that's actually very useful, it's sounding like asynchronous could be a problem. I'll have to do some small scale benchmarking but it sounds like I will have to stay away from threading sockets in this case.
Was This Post Helpful? 0
  • +
  • -

#12 vpdic  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 82
  • Joined: 24-November 13

Re: Multiple sockets and threading woes.

Posted 01 December 2013 - 04:49 PM

Actually, I'm now realizing I can make a proxy checker that will serve the same purpose. Less work and should accomplish the same thing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1