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

  • SEARCH
  • Home
  • 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 6743887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:01:02+00:00 2026-05-26T12:01:02+00:00

Iam just a beginner student socket programming.I tried a simple code from TCP/IP Sockets

  • 0

Iam just a beginner student socket programming.I tried a simple code from “TCP/IP Sockets in C# Practical Guide for Programmers” pdf book but it doesn’t work.I compiled it in visual studio 2010.Please help me what is wrong and here is the complete code

using System; // For Console, Int32, ArgumentException, Environment
using System.Net; // For IPAddress
using System.Net.Sockets; // For TcpListener, TcpClient

class TcpEchoServer {

private const int BUFSIZE = 32; // Size of receive buffer

static void Main(string[] args) {

if (args.Length > 1) // Test for correct # of args
throw new ArgumentException("Parameters: [<Port>]");

int servPort = (args.Length == 1) ? Int32.Parse(args[0]): 7;

TcpListener listener = null;

try {
    // Create a TCPListener to accept client connections
listener = new TcpListener(IPAddress.Any, servPort);
listener.Start();
} catch (SocketException se) {

Console.WriteLine(se.ErrorCode + ": " + se.Message);
Environment.Exit(se.ErrorCode);
}

byte[] rcvBuffer = new byte[BUFSIZE]; // Receive buffer
int bytesRcvd; // Received byte count
for (;;) { // Run forever, accepting and servicing connections
TcpClient client = null;
NetworkStream netStream = null;

 try {
 client = listener.AcceptTcpClient(); // Get client connection
 netStream = client.GetStream();
 Console.Write("Handling client - ");

 // Receive until client closes connection, indicated by 0 return value
 int totalBytesEchoed = 0;
 while ((bytesRcvd = netStream.Read(rcvBuffer, 0, rcvBuffer.Length)) > 0) {
 netStream.Write(rcvBuffer, 0, bytesRcvd);
 totalBytesEchoed += bytesRcvd;
 }
 Console.WriteLine("echoed {0} bytes.", totalBytesEchoed);

 // Close the stream and socket. We are done with this client!
 netStream.Close();
 client.Close();

 } catch (Exception e) {
 Console.WriteLine(e.Message);
 netStream.Close();
 }
 }
 }
 }

From Comment:

I have program for client also to connect with this server program. Actual problem is this server program does not run. At line 16-22 there is the code try

{ // Create a TCPListener to accept client connections
  listener = new TcpListener(IPAddress.Any, servPort);
  listener.Start();
} 
catch (SocketException se) 
{
  Console.WriteLine(se.ErrorCode + ": " + se.Message);
  Environment.Exit(se.ErrorCode);
}

and program show the error code and displays message like this

10048:Only one usage of each socket address is normally permitted

and program close. What to do?

  • 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-26T12:01:03+00:00Added an answer on May 26, 2026 at 12:01 pm

    If you used Visual Studio 2010 to compile and run this (via Debug), you should set up command line arguments as your code requires them.

    If you already did run your program with command line arguments (either through console or by setting them up in VS), then please give a more detailed explanation of why it doesn’t work.

    To set up command line arguments, right click on your project in Solution Explorer -> Properties, then in Debug tab, type a value representing a port in the Command Line Arguments field. No spaces, only one value.

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

Sidebar

Related Questions

Iam running WAMP server and just enabled php_memcache extension and have tried the code
I am a beginner to programming when I start to code I just start
I am just a beginner in ASP.NET. My question is simple, I wanna add
I am just a beginner at windows programming and was reading a tutorial about
I am a beginner just starting to profile my code and was confused why
i am just beginner of iphone programming . i want to get size(full size)
Hi I am a C++ beginner just encountered a problem I don't know how
I am a beginner in Haskell so please bear with me. (Just started learning
I am new to Scala, just started learning, so this is basic beginner question.
I am just beginner with Perl, so if it sounds stupid - sorry for

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.