I 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
ate.None);
ps.AddPermission(new SecurityPermission(Permiss
ionState.U
nrestricte
d));
ps.AddPermission(new SocketPermission(Permissio
nState.Unr
estricted)
);
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