Forced accept.
Computer101
EE Admin
Main Topics
Browse All TopicsI have a TCP server listening at say port 3005.Any TCP client can connect and recieve online transactions send by this server.My need is to recieve this data asyncronously in the web page and show the live transactions.
1.First method i tried was using User control(.Net Windows Control Library).
I can able to run the user control without any problem on receiving the transactions asyncronously from the server using .Net raw sockets APIs.
But when I run the same 'user control' in my web application , it throws socketpermission exception since .Net Code Access Security prevents connection to TCP ports which are not following HTTP protocols.The solution is to set the Machine Code security permissionset to "FullTrust" using caspol.exe utilty or framework console wizard.But the user at the client PC has to set this permission explicitly when he browse this control, which is not acceptable.
I read atricles that one can set the socket permission unrestricted.To set the socket permission unrestricted , one need to set the securitypermission unrestricted first.I tried this and the same problem (Socket Permission Exception).No change in adding the following sets of code in my 'User control'
/*************************
PermissionSet ps = new PermissionSet(PermissionSt
ps.AddPermission(new SecurityPermission(Permiss
ps.AddPermission(new SocketPermission(Permissio
ps.Assert();
/*************************
2.Later after working 2 to 3 days , I thought of dropping this user control logic and went for AJAX related study work to achieve this.
As per my knowlegde , I see that the client has to poll anyway to the web server to recieve any updates using JS SetTimeout method and asyncronous callbacks to prevent full page refresh.This is something like client pull method.
I need to get asynchronous call back from the server to the client side by only one event request at the first and the web server has to subsequently send the updates whenever it recieve from the TCP server connected.
I just tried this small example on a simple ASP .NET web application button event,
/*************************
Try
Dim i As Integer
For i = 1 To 10
Response.BufferOutput = False
Response.Write("hello")
Response.Flush()
Thread.Sleep(1000)
Next
Catch ex As Exception
End Try
/*************************
But the page is kept loading untill on the while llop ends and "Flush" method doesnt help as I thought.
So, the experts please give me a sloution in ASP .Net where I need to get the online transactions live on a web page without client refresh.
Is there anything like "Pushlets" of JAVA technology equivalent in .Net? i.e Instead of closing the HTTP connection after fetching an HTML page, the connection is kept open while fresh data is pushed to the client.
Experts , please help on this requirement. Experts can even please explain how to achieve the code security permission unrestricted inside the user control itself to connect to non HTTP TCP ports when called from web applicaiton.
P.S: I m not prefering for client pull method which i feel overloaded and unnecessary when the transactions occurance interval is unpredicatable.Only when the server receive the transaction , just push to the client is a best way, I feel.
Thanks and Regards,
Nagarajan S
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: AGBrownPosted on 2007-05-29 at 03:59:39ID: 19171271
Basically, I don't think its possible as you want it. ASP.NET is designed around the client-request model. The reason your while loop doesn't work is that you haven't called Response.End(), and therefore the client won't update the browser.
There are solutions, but they are imperfect and involve third-party products that make user of flash to keep a socket open. Alternatively you would have to build a bespoke server and start an ajax request on the client which kept a socket open and listened for information. This, as you probably know, is tricky as that socket will timeout at some point and you'll need to detect that and open another one.
The best way that I have found to do this is to use the MS AJAX (ajax.asp.net) framework and drop a timer with a few update panels on the page. To be honest, the performance requirements for refreshing every five seconds and keeping sockets open to the web server are going to be similar. Therefore you aren't going to have much luck trying to pump data into a webusercontrol; instances of pages and their controls only last for the duration of a request. Instead you will need an application scope object that deals with incoming data, and that pages can then poll during their refresh periods for new information. If you wanted to you could make use of the web service calls to get the information instead, all of that is taken care of in the framework.
Does that help?
Andy