Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:14:01+00:00 2026-05-30T05:14:01+00:00

Server side code: static void Main(string[] args) { static Socket sck; Console.WriteLine(Server Started…); sck

  • 0

Server side code:

static void Main(string[] args)
        {
            static Socket sck;
            Console.WriteLine("Server Started...");
            sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sck.Bind(new IPEndPoint(0, 1234));
            while (true)
            {
                sck.Listen(100);
                Socket accepted = sck.Accept();
                buffer = new byte[accepted.SendBufferSize];
                int bytesRead = accepted.Receive(buffer);
                byte[] formatted = new byte[bytesRead];
                for (int i = 0; i < bytesRead; i++)
                    formatted[i] = buffer[i];
                string strdata = Encoding.ASCII.GetString(formatted);
                Console.WriteLine(strdata + "\r");
            //    sck.Close();
            }

Client side code:

static void Main(string[] args)
        {
            static Socket sck;
            sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint localEndpt = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);
            try
            {
                sck.Connect(localEndpt);
            }
            catch
            {
                Console.Write("Unable to Connect");
            }
            while (true)
            {
                Console.WriteLine("Enter Text");
                string sendtext = Console.ReadLine();
                byte[] Data = Encoding.ASCII.GetBytes(sendtext);
                sck.Send(Data);
                Console.WriteLine("Data Sent!");
                //sck.Close();
                //Console.Read();
            }

I want to send text from the Client side multiple times, however the text is sent only the first time. Please tell me where am i going wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:14:03+00:00Added an answer on May 30, 2026 at 5:14 am

    The problem is on your server. You are in a loop listening for a new connection, accepting it and receiving data. Yet what happens is the listening statement see’s a client who wants to connect. Your accept statement actually connects the client and your receive statement receieves the first data. After that your server starts listening for a new connection again but is not receiving more data from the already existing connection. You should build a loop around the Accept statement and a loop around the Receive statement on your server to fix this problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On server side I have this code which running in new thread static void
I create a new thread that runs the following code: public static void startServer()
My server side code: [WebMethod(CacheDuration = 0, EnableSession = true)] public static int UserID()
Server side code: byte[] size = new byte[4]; size = BitConverter.GetBytes(fileData.Length); stream.Write(size, 0, 4);
Developing server side code i finally got my eyes X-crossed trying to write -
When writing server-side code you need to explicitly stop execution after sending a Location:
I am trying to figure out the efficiency of my server side code. Using
I want to ask in which phase of Control Execution Lifecycle is the Server-Side-Code
For a particular project I have, no server side code is allowed. How can
I am validating a zip code using Javascript that is generated server-side, and injected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.