Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Click here to send data to sever!! [modified]

Click here to send data to sever!! [modified]

Scheduled Pinned Locked Moved C#
csharpquestionvisual-studiosysadmintutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yum 2010
    wrote on last edited by
    #1

    hello everyone, how can i send data to server?? I am using visual studio 2010.The program is working but i am not getting the option of " click here to send data to server" in the Form1 window that comes after client-server acknowledgment.Kindly guide me. client program is

    using System;
    using System.Windows.Forms;
    using System.Net.Sockets;
    using System.Text;

    namespace WindowsApplication1
    {
    public partial class Form1 : Form
    {
    System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
    NetworkStream serverStream;

        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1\_Load(object sender, EventArgs e)
        {
            msg("Client Started");
            clientSocket.Connect("127.0.0.1", 8888);
            label1.Text = "Client Socket Program - Server Connected ...";
        }
    
        private void button1\_Click(object sender, EventArgs e)
        {
            NetworkStream serverStream = clientSocket.GetStream();
            byte\[\] outStream = System.Text.Encoding.ASCII.GetBytes("Message from Client$");
            serverStream.Write(outStream, 0, outStream.Length);
            serverStream.Flush();
    
            byte\[\] inStream = new byte\[10025\];
            serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
            string returndata = System.Text.Encoding.ASCII.GetString(inStream);
            msg("Data from Server : " + returndata);
        }
    
        public void msg(string mesg)
        {
            textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;
        } 
    }
    

    }

    the server program is

    using System;
    using System.Threading;
    using System.Net.Sockets;
    using System.Text;

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    TcpListener serverSocket = new TcpListener(8888);
    TcpClient clientSocket = default(TcpClient);
    int counter = 0;

            serverSocket.Start();
            Console.WriteLine(" >> " + "Server Started"); 
    
            counter = 0;
            while (true)
            {
                counter += 1;
                clientSocket = serverSocket.AcceptTcpClient();
                Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
                handleClinet client = new handleC
    
    L 1 Reply Last reply
    0
    • Y yum 2010

      hello everyone, how can i send data to server?? I am using visual studio 2010.The program is working but i am not getting the option of " click here to send data to server" in the Form1 window that comes after client-server acknowledgment.Kindly guide me. client program is

      using System;
      using System.Windows.Forms;
      using System.Net.Sockets;
      using System.Text;

      namespace WindowsApplication1
      {
      public partial class Form1 : Form
      {
      System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
      NetworkStream serverStream;

          public Form1()
          {
              InitializeComponent();
          }
      
          private void Form1\_Load(object sender, EventArgs e)
          {
              msg("Client Started");
              clientSocket.Connect("127.0.0.1", 8888);
              label1.Text = "Client Socket Program - Server Connected ...";
          }
      
          private void button1\_Click(object sender, EventArgs e)
          {
              NetworkStream serverStream = clientSocket.GetStream();
              byte\[\] outStream = System.Text.Encoding.ASCII.GetBytes("Message from Client$");
              serverStream.Write(outStream, 0, outStream.Length);
              serverStream.Flush();
      
              byte\[\] inStream = new byte\[10025\];
              serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
              string returndata = System.Text.Encoding.ASCII.GetString(inStream);
              msg("Data from Server : " + returndata);
          }
      
          public void msg(string mesg)
          {
              textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;
          } 
      }
      

      }

      the server program is

      using System;
      using System.Threading;
      using System.Net.Sockets;
      using System.Text;

      namespace ConsoleApplication1
      {
      class Program
      {
      static void Main(string[] args)
      {
      TcpListener serverSocket = new TcpListener(8888);
      TcpClient clientSocket = default(TcpClient);
      int counter = 0;

              serverSocket.Start();
              Console.WriteLine(" >> " + "Server Started"); 
      
              counter = 0;
              while (true)
              {
                  counter += 1;
                  clientSocket = serverSocket.AcceptTcpClient();
                  Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
                  handleClinet client = new handleC
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Can you please edit your post and use "Pre" tag to format your code so that it is easier to read/understand and give proper reply. HTH

      Jinal Desai - LIVE Experience is mother of sage....

      Y 1 Reply Last reply
      0
      • L Lost User

        Can you please edit your post and use "Pre" tag to format your code so that it is easier to read/understand and give proper reply. HTH

        Jinal Desai - LIVE Experience is mother of sage....

        Y Offline
        Y Offline
        yum 2010
        wrote on last edited by
        #3

        I have edited my post!!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups