473,221 Members | 1,574 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,221 software developers and data experts.

Want to read socket data in ASP.NET

I need to write an ASP.NET application which can do the following:

1. Create a socket which will stay alive and continously read data.
2. The data read needs to be displayed on the webpage.
3. As the data is received, it needs to be displayed as its received.

I have made an attempt, but hit a problem.

Here is a brief overview of the attempt:

1. Page_Load kicks off a thread for the socket handling. The socket is
static.
Its sits and reads data and caches the bytes read in an ArrayList
(also static).

2. When a postback is fired (I am using an Atlas timer to prevent a full
postback) I clear the Listbox component
for displaying the socket data and then bind the ArrayList to the
Listbox to display.

This does appear to work but at different intervals, I get a message box
box indicating unknown error.

If I take the code out for dsiplaying the Listbox, the data continues to
cache, but I cant think of a way of displaying.

Anyone know why this is happening, or suggest an alternative to my
problem?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Jul 19 '06 #1
5 2022
Steven,

ASP.NET is definitely not the place to do this, not only for security
reasons (the security model of ASP.NET doesn't really make it easy to open a
socket to listen to), but because of the nature of the web. You can't push
things to the browser unless a request is made, so having a socket sit on
your page waiting for requests is just a bad idea.

Rather, you should have a service that handles this aspect (the reading
of bytes off the socket) and writes the information to some shared resource
(file, database, whatever) which the ASP.NET app can then read from and push
to the page when requested.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steven Blair" <st**********@btinternet.comwrote in message
news:uK**************@TK2MSFTNGP03.phx.gbl...
>I need to write an ASP.NET application which can do the following:

1. Create a socket which will stay alive and continously read data.
2. The data read needs to be displayed on the webpage.
3. As the data is received, it needs to be displayed as its received.

I have made an attempt, but hit a problem.

Here is a brief overview of the attempt:

1. Page_Load kicks off a thread for the socket handling. The socket is
static.
Its sits and reads data and caches the bytes read in an ArrayList
(also static).

2. When a postback is fired (I am using an Atlas timer to prevent a full
postback) I clear the Listbox component
for displaying the socket data and then bind the ArrayList to the
Listbox to display.

This does appear to work but at different intervals, I get a message box
box indicating unknown error.

If I take the code out for dsiplaying the Listbox, the data continues to
cache, but I cant think of a way of displaying.

Anyone know why this is happening, or suggest an alternative to my
problem?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***

Jul 20 '06 #2
I understand it is not ideal to have this in ASP.NET, but would be very
beneficial to the company to have this.
Security is not so much a problem. The proposed application can only
ever be run locally on our intranet and its not sensitive data being
viewed.
We already have a service which collects the messages, then sends it out
on a specified port which the application will connect to to view. (At
the moment its a windows program doing this job).
Having a shared file / database brings its own problems of how we track
which lines have been displayed and also, the main point of it having to
be real time messages being displayed (I don't think caching to a
database, then retrieving would be suitable)

*** Sent via Developersdex http://www.developersdex.com ***
Jul 20 '06 #3
I think you're going to have to identify the "unknown error." In addition, I
don't see any reason why the Socket or ArrayList needs to be static; this
could be causing some issue. But without specific information about the
problem occurring, we can only guess.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
"Steven Blair" <st**********@btinternet.comwrote in message
news:uK**************@TK2MSFTNGP03.phx.gbl...
>I need to write an ASP.NET application which can do the following:

1. Create a socket which will stay alive and continously read data.
2. The data read needs to be displayed on the webpage.
3. As the data is received, it needs to be displayed as its received.

I have made an attempt, but hit a problem.

Here is a brief overview of the attempt:

1. Page_Load kicks off a thread for the socket handling. The socket is
static.
Its sits and reads data and caches the bytes read in an ArrayList
(also static).

2. When a postback is fired (I am using an Atlas timer to prevent a full
postback) I clear the Listbox component
for displaying the socket data and then bind the ArrayList to the
Listbox to display.

This does appear to work but at different intervals, I get a message box
box indicating unknown error.

If I take the code out for dsiplaying the Listbox, the data continues to
cache, but I cant think of a way of displaying.

Anyone know why this is happening, or suggest an alternative to my
problem?

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***

Jul 20 '06 #4
This unknown error is causing me a lot of pain.
I even tried putting try catch all round my code to see if it would
break out and tell me the problem.

If my socket and ArrayList is not static, how would both object surive
after the postback has been finished and my page goes out of scope?

Maybe I am a little confused. Perhaps if I declared my socket within the
thread method, and the thread method could perhaps write out to the
Session.

On the next postback I could read the data from the Session to the
screen, then clear the Session value to continue (this would be locked
as I was doing this!)

*** Sent via Developersdex http://www.developersdex.com ***
Jul 20 '06 #5
There are lots of ways to avoid making your Socket class static. You can
store an instance in the Application Cache, create a Service, or use
Remoting.

Using a Thread is not going to be a good idea, if the Thread is spawned by a
Page class. Can you at least give us the text of the error you *do* see?
Also, how are you clearing this ArrayList after reading from it? It sounds
like you may possibly be experiencing a memory fragmentation issue. Memory
fragmentation occurs when an object remains in memory, but continually
de-allocates and re-allocates memory. Because the object itself is never
released, memory gets fragmented. You may find the following article
helpful: http://www.vsj.co.uk/dotnet/display.asp?id=284

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

What You Seek Is What You Get.
"Steven Blair" <st**********@btinternet.comwrote in message
news:O4**************@TK2MSFTNGP02.phx.gbl...
This unknown error is causing me a lot of pain.
I even tried putting try catch all round my code to see if it would
break out and tell me the problem.

If my socket and ArrayList is not static, how would both object surive
after the postback has been finished and my page goes out of scope?

Maybe I am a little confused. Perhaps if I declared my socket within the
thread method, and the thread method could perhaps write out to the
Session.

On the next postback I could read the data from the Session to the
screen, then clear the Session value to continue (this would be locked
as I was doing this!)

*** Sent via Developersdex http://www.developersdex.com ***

Jul 20 '06 #6

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

Similar topics

2
by: zb011 message | last post by:
Hi all, I have coded an outbound Socket program in C on a solaris box that sends out data and receives an acknowledgement for it. However, have faced this problem of a "HANG" state, whereby...
4
by: Ollie Cook | last post by:
Hi, I am having some difficulty with read(2) and interrupting signals. I expect I am misunderstanding how the two work together, so would appreciate some guidance. I am trying to 'time out' a...
0
by: Tomasz Naumowicz | last post by:
Hello Everybody, I have the following problem with sockets. Socket.Available reports data in the buffer (e.g. 1849 bytes) but Socket.Read throws an exception because the connection is already...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
5
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable...
2
by: White Spirit | last post by:
I have a function within an application where a client connected to a server continuously sends data. The code on the server side is of the following form: Socket socket = receiveSocket;...
2
by: Giulio Petrucci | last post by:
Hi everytbody, I'm experiencing some problems trying to asynchronously read data from a Socket object. What I do now is: 1) call th BeginReceive(...) method on the Socket object; 2) within the...
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
0
by: kaps | last post by:
Hi, How do I read data from perl socket. I tried these three methods in bold but nothing worked. use strict; use IO::Socket; use HTTP::Request::Common; use LWP::UserAgent;
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.