473,386 Members | 1,752 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,386 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 2028
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;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.