473,385 Members | 2,029 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,385 software developers and data experts.

Streaming time

17
hi,
Lemme give u a little background on my problem. Ive created a client and server applications that receive and stream live time values. The client software is a clock that receives the time and displays it in a wpf app. Now when i use the DateTime.Now on the client app locally without using streaming the clock works great. However when I stream it from a server app which is also running on my computer or on a remote computer there is tremendous lag. That means, the time on the client app is updated at random intervals and not every second. Although when it updates, it updates to the correct time, but it doesnt tick like a normal clock should. Hope this makes sense...lol. Furthermore, when the client app receives the time, it displays the same time multiple times rather than just one line. Overall, the display is very ugly and the streaming is abysmal. Ive posted all my code, any suggestions on how to solve my problem. Thanks.

The client display app:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Windows.Threading;
  15. using System.Threading;
  16.  
  17. namespace MainClock
  18. {
  19.     /// <summary>
  20.     /// Interaction logic for Window1.xaml
  21.     /// </summary>
  22.     public partial class Window1 : Window
  23.     {
  24.         Client c = new Client();
  25.  
  26.         public Window1()
  27.         {
  28.             InitializeComponent();
  29.  
  30.             DispatcherTimer timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
  31.             {
  32.                this.label1.Content = getDateTime();
  33.              }, this.Dispatcher);
  34.         }
  35.  
  36.         public String getDateTime()
  37.         {
  38.             return c.getData();
  39.         }
  40.  
  41.         private void Window_Loaded(object sender, RoutedEventArgs e)
  42.         {
  43.         }
  44.  
  45.         private void button1_Click(object sender, RoutedEventArgs e)
  46.         {
  47.             c.endConnection();
  48.         }
  49.     }
  50. }
  51.  
The client app that receives data from the server

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Net.Sockets;
  7.  
  8. namespace MainClock
  9. {
  10.     class Client
  11.     {
  12.         IPEndPoint ip;
  13.         Socket server;
  14.         byte[] data;
  15.         int receivedDataLength;
  16.  
  17.         public Client()
  18.         {
  19.             ip = new IPEndPoint(IPAddress.Parse("130.63.184.179"), 9999);
  20.  
  21.             server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  22.  
  23.             try    
  24.             {
  25.                 server.Connect(ip);
  26.             }
  27.             catch (SocketException e)
  28.             {
  29.                 //Console.WriteLine("Unable to connect to server.");
  30.                 return;
  31.             }
  32.     }
  33.  
  34.      public string getData()
  35.      {
  36.         data = new byte[1024];
  37.  
  38.         receivedDataLength = server.Receive(data);
  39.  
  40.         string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
  41.  
  42.         return stringData;
  43.     }
  44.  
  45.     public void endConnection()
  46.     {
  47.         server.Shutdown(SocketShutdown.Both);
  48.         server.Close();
  49.       }
  50.     }
  51. }
  52.  
The Server command line prog that streams the time
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Net.Sockets;
  7.  
  8. namespace ClockServer
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
  15.             Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  16.  
  17.             socket.Bind(ip);
  18.            socket.Listen(10);
  19.  
  20.             Console.WriteLine("Waiting for a client...");
  21.  
  22.             Socket client = socket.Accept();
  23.  
  24.             IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;
  25.  
  26.            Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port);
  27.  
  28.             Clock c = new Clock();
  29.  
  30.         //This is just a sort of timer that keeps the connection alive for 100000 counts. Its a stop gap arrangement.
  31.             for (int i = 0; i < 100000; i++)
  32.             {
  33.                 string time = c.getHour() + ":" + c.getMinutes() + ":" + c.getSeconds();
  34.                 string date = c.getDay() + "-" + c.getMonth() + "-" + c.getYear();
  35.                 string dateTime = time + " EDT( -5GMT)\n" + date;
  36.                 byte[] data = new byte[1024];
  37.  
  38.                 data = Encoding.ASCII.GetBytes(dateTime);
  39.  
  40.                 client.Send(data, data.Length, SocketFlags.None);
  41.              }
  42.  
  43.             Console.WriteLine("Disconnected from {0}", clientep.Address);
  44.             client.Close();
  45.             socket.Close();
  46.         }
  47.     }
  48. }
  49.  
The clock prog that runs on the server side and generates the time values.
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ClockServer
  7. {
  8.     class Clock
  9.     {
  10.         public Clock()
  11.         {
  12.         }
  13.  
  14.         public String getHour()
  15.         {
  16.             return DateTime.Now.Hour.ToString();
  17.         }
  18.  
  19.         public String getMinutes()
  20.         {
  21.         return DateTime.Now.Minute.ToString();
  22.         }
  23.  
  24.         public String getSeconds()
  25.         {
  26.             return DateTime.Now.Second.ToString();
  27.         }
  28.  
  29.         public String getDay()
  30.         {
  31.             return DateTime.Now.Day.ToString();
  32.         }
  33.  
  34.         public String getMonth()
  35.         {
  36.             return DateTime.Now.Month.ToString();
  37.         }
  38.  
  39.         public String getYear()
  40.         {
  41.             return DateTime.Now.Year.ToString();
  42.          }
  43.     }
  44. }
  45.  
Jul 18 '08 #1
2 1710
Bubbs
17
The client app that displays the time is a WPF app. This is the C# code for the app. The client app that receives the stream is just a C# class.
The server app that transmits the stream is a C# command line prog and the Clock class is just a C# class.
The whole thing is coded in visual c# 2008 express.
Jul 18 '08 #2
Plater
7,872 Expert 4TB
Do you need to call an .Update() on your label to force it to update itself each time? It could just be that your code continues on before the update message gets sent to the label?

Also: wouldn't it be easier to just send the ticks value over the internet, rather then a formatted string?
Jul 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lonewolf | last post by:
Hi everyone, pls forgive me for my lack of knowledge and skills if my question sounds very stupid. I am trying to implement a video conferencing software and I am currently looking at a few set of...
5
by: John | last post by:
Hi all, I have an (well, what I think to be, at least) interesting question: Is it possible to stream data down to the client and, after a certain amount of data has been streamed, allow the...
6
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
8
by: poorna | last post by:
hi all i want to upload the video files to the server.. then i encode all the video files into flv files ... and then i am go to streaming ... in the mean while i create the thumbnail image...
4
by: Daniel Marious | last post by:
Hi, I'm looking for a .Net/COM component which would allow a .Net programmer with no streaming experience to be able to save online streams to local resources (files or to DB). I know that if...
8
by: Tony K | last post by:
Is streaming audio capable in asp.net 2.0 / AJAX? What I mean by streaming audio is: ability to play one or more songs back to back...or maybe even let the user select several songs to play and it...
5
by: pmakoi | last post by:
dear all this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic I am...
3
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years...
0
by: tony_in_da_uk | last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and got a near-flippant response from someone who clearly didn't take the time to consider the import. I replied, and it's still not...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.