Streaming Image From Server

Plz help me in image strwaming

Page 1 of 1

2 Replies - 1485 Views - Last Post: 11 July 2010 - 06:00 AM Rate Topic: -----

#1 jerikoboy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 16-April 10

Streaming Image From Server

Posted 11 July 2010 - 12:22 AM

hello!
i am making a client server application in which the server desktop image is load in the client picbox... but i have problem when i do that my client application is halted no image is seen can anyone help me out here is the client and server code. My server programs takes the pic of my desktop and send that to Client... THe same image after 1sec time plz help

SERVER SIDE:=
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace Server
{
    public partial class Form1 : Form
    {
        TcpListener listener = new TcpListener(IPAddress.Any, 5000);
        TcpClient tc;
        NetworkStream ns;
        Image img;
        public Form1()
        {
            InitializeComponent();
        }
                private void button1_Click(object sender, EventArgs e)
        {                                                
            TcpListener listener = new TcpListener(IPAddress.Any, 5000);
            listener.Start();
            while (true)
            {
              tc = listener.AcceptTcpClient();
                ns = tc.GetStream();
                byte[] btfromc = new byte[100];
                ns.Read(btfromc, 0, btfromc.Length);
                string strfromc = Encoding.UTF8.GetString(btfromc);
                MessageBox.Show(DateTime.Now.ToShortTimeString() + "\nClient: " + strfromc);
                timer2.Enabled = true;
                ns.Close();
                tc.Close();
                
            }
        }

                private void timer1_Tick(object sender, EventArgs e)
                {
                    String fileloc = label3.Text;
                    String fnum = label2.Text;
                    String fformate = label1.Text;
                    Size screensize = new Size(1280, 1024);
                    Bitmap BMP = new Bitmap(1280, 1024);
                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(BMP);
                    g.CopyFromScreen(new Point(0, 0), new Point(0, 0), screensize);
                    BMP.Save(fileloc+fnum+fformate );
                                      timer1.Interval = 500;
                                     
                }

                private void Form1_Load(object sender, EventArgs e)
                {
                    label1.Visible = false;
                    label2.Visible = false;
                    label3.Visible = false;
                    timer1.Enabled = true;
                }

                
                private void button2_Click(object sender, EventArgs e)
                {
                    Real_IP mynewform=new Real_IP();
                    mynewform.Show();

                }

                private void timer2_Tick(object sender, EventArgs e)
                {
                    img = Bitmap.FromFile(@"C:\0.jpg");
                    MemoryStream s = new MemoryStream();
                    img.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] btback = s.ToArray();
                    ns.Write(btback, 0, btback.Length);
                    timer2.Interval = 800;
                    
                }

               
        }
    }


Client Side:=

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.IO;

namespace client
{
    public partial class Form1 : Form
    {
        NetworkStream ns;
        TcpClient client;
        byte[] btsend;
        byte[] imgsize;
        Bitmap res;
        MemoryStream ms = new MemoryStream();
        int gotCount = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            client = new TcpClient(textBox1.Text, 5000);
             ns = client.GetStream();
            btsend = Encoding.UTF8.GetBytes("Can u Allow me????");
            try
            {
               ns.Write(btsend, 0, btsend.Length);
            }
            catch (SocketException ____)
            {
               MessageBox.Show(____.Message);
            }          
       
           imgsize = new byte[1024];
                       
      
           //do loop to get all stream data from server, each time read 1024 size data
           
            

        }

        private void timer1_Tick(object sender, EventArgs e)
                    {
                        try
            {

                gotCount = ns.Read(imgsize, 0, imgsize.Length);
                ms.Write(imgsize, 0, gotCount);
                
                if (gotCount == 0)
                   
                timer1.Enabled = false;
            }

            catch (Exception e1)
            {
                string s = e1.Message;
                s = e1.StackTrace;
                
            }


                        timer1.Interval = 1000;
                        res = new Bitmap(ms);
                        pictureBox1.Image = res;
                        pictureBox1.Invalidate();                      
            ns.Close();
            client.Close();
        }
                                                 

        }
    }




Is This A Good Question/Topic? 0
  • +

Replies To: Streaming Image From Server

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Streaming Image From Server

Posted 11 July 2010 - 12:30 AM

Moving to regular C# forum. The C# Programmers Forum is for discussions on more advanced topics and isn't the place to ask your programming help topics. From the rules of this forum:

Quote

Welcome to the C# Programmers Forum on Dream.In.Code. This forum isn't for homework questions or looking for help. This forum is for more advanced topics, and in-depth discussion of C#. If you have homework or other help related questions please post them in the C# Forum.

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • Joined: 23-August 08

Re: Streaming Image From Server

Posted 11 July 2010 - 06:00 AM

imgsize = new byte[1024];
//do loop to get all stream data from server, each time read 1024 size data


Well ya, you haven't written any code to get the data from the server!

Some potential help here
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1