Socket programming in asp.net ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I am new to .net technologies.

ASP.NET supports socket programming like send/receive in c or c++?

I am developing web-site application in asp.net and code behind is Visual
C#. In page_load event, I am using atl com component. Here one for loop is
there. In this for loop, number of iterations are 1000, I can receive some
data using com component. It is just set of some characters like
"0123456tyu".
(This is related to IIS Server machine).

My requiremnet: I have to send this data to users machine and there I need
to create one text file then I want to write this received data into this
text file.
(This is related to users machine. I mean, web pages are accessed from this
machine)

Is there any way to receive data from iis server to users machine like
socket programming in c or c++?

How can I achieve this? What technologies I have to select from VS2005?

Any suggestions are welcome.

Thanks in advance.
 
Hi Juan T. Llibre,

Thank you for your prompt response.

I am new to .NET technologies. Sorry if I am asking very basic questions.

I have one more doubt. For example I deployed one website (www.xyz.com)
in USA. Now, john is the user. He is accessing this web-site from UK. I need
to send some data from USA to UK when user clicked on button. In my web-site
application (code-behind is Visual C#), I can send data using
system.net.sokets namespace. But, How do I receive that data in UK machine?
Which technology I should use to get the data from USA to UK? ( i mean,
JAVASCRIPT or AJAX or etc....).

Thanks in advance.
--
Thanks & Regards,
John.


Juan T. Llibre said:
re:
ASP.NET supports socket programming like send/receive in c or c++?

Yes. Use System.Net.Sockets:

http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx?namespace=System.Net.Sockets




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
re:
How do I receive that data in UK machine?

The user's browser can receive the data via http.

You will need to create a page which receives a query
for data and returns the data to the client as a network stream.

Something like this :

TcpClient tcpc = new TcpClient(server, 43);
NetworkStream stream = tcpc.GetStream();
StreamWriter writer = new StreamWriter(stream);
StreamReader reader = new StreamReader(stream);

etc...

re:
Which technology I should use to get the data from USA to UK?

You use C# and the .Net Framework classes to build your ASP.NET page.

re:
JAVASCRIPT or AJAX

You don't need either of them, although you could use Ajax.

Here's a good basic introduction to programming system.net.sockets in C#:

http://www.developerfusion.co.uk/show/3918/

Read the 4 parts of the article and download/practice with the sample code provided.
When you've done that, socket programming concepts in c# will be clearer.

The example is for a Windows Forms (desktop) program,
but the same classes can be used in an ASP.NET application, using network streams.

Peter Bromberg has a good VB.NET sample at :

http://www.eggheadcafe.com/articles/20020323.asp

This Google search returns many hits with sample code:

http://www.google.com/search?hl=en&q="socket+programming"+"asp.net"

Try some of them.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
John said:
Hi Juan T. Llibre,

Thank you for your prompt response.

I am new to .NET technologies. Sorry if I am asking very basic questions.

I have one more doubt. For example I deployed one website (www.xyz.com)
in USA. Now, john is the user. He is accessing this web-site from UK. I need
to send some data from USA to UK when user clicked on button. In my web-site
application (code-behind is Visual C#), I can send data using
system.net.sokets namespace. But, How do I receive that data in UK machine?
Which technology I should use to get the data from USA to UK? ( i mean,
JAVASCRIPT or AJAX or etc....).

Thanks in advance.
 
ASP.NETsupportssocketprogramming like send/receive in c or c++?
Given the disconnected model of HTTP I would avoid hosting sockets
within premises of asp.net worker process.
My requiremnet: I have to send this data to users machine and there I need
to create one text file then I want to write this received data into this
text file.
(This is related to users machine. I mean, web pages are accessed from this
machine)
If the requirements is such that you have to interface this through
ASP.NET I would decouple the socket read write process from the web
application. The service may represent a remoting service or web
service (depending on the nature/size of audience you application
serves). If security is a concern deploy the remoting service over
IIS.
Is there any way to receive data from iis server to users machine likesocketprogramming in c or c++?
How can I achieve this? What technologies I have to select from VS2005?
However, why do you want to do this through sockets? Are you forced by
design or do you have process on other end sending data packets
through sockets?
If sockets are optional and scalability (& size of data) isn't an
issue I would consider possibilities of streaming data through
HTTPWebRequest.GetRequestStream () /
HTTPWebResponse.GetResponseStream().

Raaj.
 
Hi Juan T. Llibre,

Thank you.

.NET 2.0 framework should be there in user's machine if I use
socket programming to receive data in user's machine?

I have experience in VC++ stand-alone applications.
 
The .Net framework may not necessarily be on the end-user's machine, it's
likely, but not necessarily a guarantee.

Keep in mind that if you're familiar with VC++ stand-alone applications you
can easily use those as well...you dont' have to use the .Net framework.

Your system seems kind of bizarre, though; remember that a web browser is
already a network-based application, why are you building something from the
ground up using sockets?
 
Hi Ben Rush,

Thank you. I am new to .net technologies.

Can I create/write a file in the end-user's machine, When the user
requests a page in a web-site?

Let me explain where I stucked. I have atl com dll.It will be there
in IIS Machine. ATL COM DLL can receive some data through socket programming
in for loop of button_click event in aspx page. Here, I want to send this
data from IIS Machine to end-user's machine, then create/write the file with
this data received from IIS server machine. This is my requirement. Is it
possible in asp.net and Visual C#?

If it possible, My doubt is where can I receive this data in
web-application? In visual C++ application, I have two applications which are
client and server applications. We can send data in server using send
function and receive data in client using client function of winsock. but, in
web-based application where I can receive that data like in client
application(VC++). Where is client portion of code area to communicate with
server in web-application?

Sorry I ask very basic questions.

Thanks in advance.
 
Hi.

Actually your questions are very, very basic - which is okay, but I think
means you may be missing the point on a few very fundamental issues.

It's not the nature of a web browser-based application, typically, to
integrate too tightly with the machine it's running on. This is the case for
many reasons - one of the most important being security - but also because
the general paradigm here is that you can visit a web page from any type of
operating system (Linux, Windows, Mac, etc) and making too many assumptions
about the client itself is often complex. Much care has been taken over the
years to make developing simple web pages (made of HTML and JavaScript) look
and behave the same across platforms; writing a system which is founded upon
much more than that would be even more complicated.

It can be done, though - but it's not ever going to be a steady,
platform-independent solution.

But what it seems like you're after is something very bizarre to me - you're
trying to get the IIS server to initiate contact with a client machine;
which is not something you do very often. IIS is built and secured as a web
server, and your client machines will more than likely be behind NATs,
firewalls, or may not even be turned on - it seems convoluted from my
perspective to expect that a client's machine will always be on and that you
can connect to it. Though clearly possible (that is, connecting to a machine
from a web server using sockets), it's not something I would recommend from
a conceptual or security standpoint.

Why not try something different? If you have the web server parsing and
holding this data - why not have the client machine periodically check in
with the server using a simple web request or web service request, download
the data, and do with it what is necessary? Do you really need things to be
instantaneous? Make the client machines "phone home" periodically.

The web is a very, very disconnected medium; and for security reasons people
have really locked the web down. Creating a reverse connection from the
server to the client is just going to be a real pain in the arse.
 
Back
Top