views:

77

answers:

2

Hi I need a sample application of the following scenario
1) IOCP TCP Server capable of accepting request
2) client make request and send receive operation
3) SERVER close the connection
4) client open another socket for connection and do send receive operation

With this example i want to see how a client can open a connection and after server close that connection another successful connection can made with client and again do send receive operation
How actually server can handle discarded connection and sockets the remains open unwanted ??

Please Please help me with that
This can blow a new soul in my body !!!!

+1  A: 

This article should give you a start

BioBuckyBall
It's ok, but there's nothing there about I/O Completion Ports. Then again, I don't know that IOCP, as such, is supported in .NET.
Steven Sudit
+1  A: 

I wrote a series of articles on The Code Project several years ago which presented a set of code for building IOCP based TCP servers. The code is in C++ and your question is tagged ".net" but it would seem unlikely that you'd want to develop a .Net server using IOCP directly since you could use the various async socket methods to do the same thing without needing to get your hands dirty with the actual IOCP side of things.

Anyway...

The first article is here: http://www.codeproject.com/KB/IP/jbsocketserver1.aspx

I've since updated the code a little and it can be found here.

There's no client code, but you can connect to the server with telnet and send and recv data...

Len Holgate
I just want to know how it handles discarded connections this is very important, suppose a hacker tries to open 1000 connection to my server and after server rejecting that but the socket creating that connection is still connecting and i think it use server resources as you can see with netstat command
Ehsan
It all depends how you write the server. If a client opens 1000 connections and does nothing then those connections WILL be using up server resources. Perhaps your server has a protocol that requires a login, you could ensure that the connection cant stay at the 'pre login' stage for more than x seconds and disconnect them if they do... It's nothing to do with the IOCP side of things how you handle this kind of situation you would get the same problems with an old school thread per connection or select based server.
Len Holgate