• 0

ASP CHat


Question

ive been looking at alot of asp chat tutorials online and im repeatedly seeing models where the chat input is stored to a database, then called by a meta refresh every 5-8 seconds, this is all well and good, but is there a different way to go about this, maybe one with more instantaneous results,

and possibly without database support,

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/
Share on other sites

11 answers to this question

Recommended Posts

  • 0

well you could always:

1) store the conversation history for each chat session in a flat file

2) periodically have a javascript function load that file via a hidden iframe and send the data back

3) compare the data in the chat container (possibly a div) to the returned data

4) if the data is different then dynamically swap out the data, else do nothing

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/#findComment-588145129
Share on other sites

  • 0

Can you use ajax with asp? I started a php chatroom, and started using ajax to do the job. Ajax did a good job of doing it all. Searched for a new post every 3 seconds or so, if one was there, used javascript to add one to the page, without refreshing it. I'm assuming can work with asp too.

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/#findComment-588145633
Share on other sites

  • 0

You will need to use sockets and have some form of socket server. A socket server is a constant connection allowing near instant communication. Never done it in ASP before but have in many other languages, actually working on one at the moment with flash and a VB server. Once set up its easily expandable into many other applications!

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/#findComment-588145638
Share on other sites

  • 0
  ncc50446 said:

Can you use ajax with asp? I started a php chatroom, and started using ajax to do the job. Ajax did a good job of doing it all. Searched for a new post every 3 seconds or so, if one was there, used javascript to add one to the page, without refreshing it. I'm assuming can work with asp too.

Yes, you can use ajax with asp. I've been thinking about doing this with ASP.NET, myself.

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/#findComment-588146004
Share on other sites

  • 0

There are some simple java socket servers around, i have one somewhere, but just google it. All they do (the simple style) is broadcast what ever message it recieves to all of the sockets connected to it. So you send messsages in XML form. "<MSG>Hey how are you?</MSG><FROM>da13ro</FROM>"

Right? Then you have to set up asp to have a OnData handler to process it all when a packet comes in. Not sure if asp needs it but i know FLASH wont interpret and call the onData even unless the xml string is terminated with a null character "chr(0)" in VB.

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/#findComment-588148121
Share on other sites

  • 0

OK: Heres What i got:

Server Side:

Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Timers
Imports System.IO



Module ChatEngine
	Dim LocalHost As System.Net.IPAddress = IPAddress.Parse("127.0.0.1im ChatServer As New TcpListener(LocalHost, 81)
	Dim Client As TcpClient
	Dim Ticker As New System.Timers.Timer()
	Dim Message As String


	Sub Main()
		AddHandler Ticker.Elapsed, AddressOf Ticker_Tick
		Ticker.Interval = (2000)
		Ticker.Enabled = True

		Dim ListThread As New Thread(New ThreadStart(AddressOf StartListening))
		ListThread.Start()

		Console.WriteLine("Press the Enter key to exit the program.")
		Console.ReadLine()
	End Sub

	Public Sub StartListening()
		ChatServer.Start()
	End Sub

	Private Sub Ticker_Tick(ByVal source As Object, ByVal e As ElapsedEventArgs)


		If ChatServer.Pending Then
			Message = ""
			Client = ChatServer.AcceptTcpClient()

			'Dim Reader As New StreamReader(Client.GetStream())
			'While Reader.Peek &gt; -1
			'	Message = Message + Convert.ToChar(Reader.Read()).ToString
			'End While

			Console.WriteLine("Connection Established " &amp; Client. )
		End If
	End Sub
End Module

Client Side:

Imports System.Net.Sockets

Module Module1

	Sub Main()
		Dim Client As New TcpClient
		Client.Connect("127.0.0.1", 81)


		Console.WriteLine("Connected: Press the Enter key to exit the program.")
		Console.ReadLine()
	End Sub

End Module

where do i need to go from here

Link to comment
https://www.neowin.net/forum/topic/522415-asp-chat/#findComment-588158954
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.