473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Writing a TCP server - Now understanding it:)

Hello

I just wrote a TCP server.
For that I used MSDN sample.
So, I have a asyncron server. As they say in MSDN, I have this methods:

----------------------
Private Sub StartListening() that is the entry point of the server main
thread.
Private Sub AcceptCallback(ByVal ar As IAsyncResult)
Private Sub Receive(ByVal ar As IAsyncResult)
Private Sub Send(ByVal handler As Socket, ByVal data As Byte())
Private Sub SendCallback(ByVal ar As IAsyncResult)
-----------------------

Now, I start the server with StartListening.
When a connection was made, the socket that listen call the AcceptCallback
in a new thread.
AcceptCallback create a new socket "handler" and pass it forward to
BeginReceive end finish it's thread.
Then Receive is called in a new thread, the "handler" socked is extracted
from the parameter, finish the receive, read the data and process it...
The response is prepared to be send with Send method, using the same
"handler" socket (handler.BeginSend(...)). Here, the receive thread is
finished.
When send is finished, the SendCallback is called in a new thread, the
"handler" is activated again from parameter, handler.EndSend finish the
send. Here the "handler" is shutdown and closed.

Here coms the questions:
This system is connectionless, right?
If so, how can I make it "Keep-Alive"?
I use WebClient for client requests. That class keep the connection opened
if I dont close the "handler"?
I can reuse this handler for further requests?
How the Server, as it is now, will react on such cases, because I see that
any new request spawn a new thread with a new handler, so, what happend with
the first handler socket?
Thanks if you read all this,
more many thanks if you will illuminate me :)
--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
2 1479
I noticed from another sample the fact that to keep connection alive they
just make another call to beginReceive with the same "handler" socket.
WebClient keep the first socked open until the server close it and use the
same one everytime it need?

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello

I just wrote a TCP server.
For that I used MSDN sample.
So, I have a asyncron server. As they say in MSDN, I have this methods:

----------------------
Private Sub StartListening() that is the entry point of the server main
thread.
Private Sub AcceptCallback(ByVal ar As IAsyncResult)
Private Sub Receive(ByVal ar As IAsyncResult)
Private Sub Send(ByVal handler As Socket, ByVal data As Byte())
Private Sub SendCallback(ByVal ar As IAsyncResult)
-----------------------

Now, I start the server with StartListening.
When a connection was made, the socket that listen call the AcceptCallback
in a new thread.
AcceptCallback create a new socket "handler" and pass it forward to
BeginReceive end finish it's thread.
Then Receive is called in a new thread, the "handler" socked is extracted
from the parameter, finish the receive, read the data and process it...
The response is prepared to be send with Send method, using the same
"handler" socket (handler.BeginSend(...)). Here, the receive thread is
finished.
When send is finished, the SendCallback is called in a new thread, the
"handler" is activated again from parameter, handler.EndSend finish the
send. Here the "handler" is shutdown and closed.

Here coms the questions:
This system is connectionless, right?
If so, how can I make it "Keep-Alive"?
I use WebClient for client requests. That class keep the connection opened
if I dont close the "handler"?
I can reuse this handler for further requests?
How the Server, as it is now, will react on such cases, because I see that
any new request spawn a new thread with a new handler, so, what happend with the first handler socket?
Thanks if you read all this,
more many thanks if you will illuminate me :)
--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #2
Nobody help me here?

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello

I just wrote a TCP server.
For that I used MSDN sample.
So, I have a asyncron server. As they say in MSDN, I have this methods:

----------------------
Private Sub StartListening() that is the entry point of the server main
thread.
Private Sub AcceptCallback(ByVal ar As IAsyncResult)
Private Sub Receive(ByVal ar As IAsyncResult)
Private Sub Send(ByVal handler As Socket, ByVal data As Byte())
Private Sub SendCallback(ByVal ar As IAsyncResult)
-----------------------

Now, I start the server with StartListening.
When a connection was made, the socket that listen call the AcceptCallback
in a new thread.
AcceptCallback create a new socket "handler" and pass it forward to
BeginReceive end finish it's thread.
Then Receive is called in a new thread, the "handler" socked is extracted
from the parameter, finish the receive, read the data and process it...
The response is prepared to be send with Send method, using the same
"handler" socket (handler.BeginSend(...)). Here, the receive thread is
finished.
When send is finished, the SendCallback is called in a new thread, the
"handler" is activated again from parameter, handler.EndSend finish the
send. Here the "handler" is shutdown and closed.

Here coms the questions:
This system is connectionless, right?
If so, how can I make it "Keep-Alive"?
I use WebClient for client requests. That class keep the connection opened
if I dont close the "handler"?
I can reuse this handler for further requests?
How the Server, as it is now, will react on such cases, because I see that
any new request spawn a new thread with a new handler, so, what happend with the first handler socket?
Thanks if you read all this,
more many thanks if you will illuminate me :)
--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Daniel Polansky | last post by:
Is there a way to open file for writing so that the opening fails if the file already exist? This needs to be atomic operation so that it is possible to use the file as a semaphore. As a result,...
3
by: mvivar | last post by:
Dear guys: First of all, I have to thank all of you, because I have found lots of answers since months without having to call your attention to me until now. I have a database in access 97...
15
by: joun | last post by:
Hi all, i want to create in my asp.net application a custom server variable, so i can retrieve later in other pages (even asp or perl) with request.servervariables("HTTP_mycustomvariable") ...
5
by: NickName | last post by:
Probably this question has been asked hundreds of times and yet net search has not generated satisfactory enough answer, at least, to me. And OK, let's assume your organization has more than 200...
22
by: Bob and Sharon Hiller | last post by:
I have an ASP page that was done in VBScript It is setup to read an Access database and I need to change it to read a Sql 2005 Database. The code that is used to open the Access Database: Set...
7
by: ivo | last post by:
Hi everyone I am having trouble with deploying VS 2005 Express Edition web app to real server on the net. Since VS 2005 ExpressEdition is free - is it for that reason unpossible to do...
1
by: samuelpaulc | last post by:
Hi everybody I REALLY need your help. Am new to VB.NET and i am asked to create XML file using DOM objects. I just for now want to know how to create a flie looking like this <?xml...
3
by: krishnakant Mane | last post by:
hello, searched a lot of places including google search but can't find answers to python-rpc. I am also very new to rpc. I am very clear about its meaning and where it is to be used, but not...
9
by: amanjsingh | last post by:
Does anyone know how to cache (or download and overwrite) a file from internet periodocally withouth using any server side script (PHP, ASP Coldfusion etc)? I want to display RSS feeds on my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.