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 97169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:57:11+00:00 2026-05-10T23:57:11+00:00

Ok, simple problem hopefully. I have started to make a simple server for a

  • 0

Ok, simple problem hopefully. I have started to make a simple server for a simple MORPG game im making, the client connected, and then disconnects, simple, the server catches the new client, but doesn’t catch when it disconnects, whats wrong?

Im hoping its something stupidly obvious.

Here’s my server code:

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; using System.Threading;  namespace ChaWilPeiBle {     public partial class MainForm : Form     {         public bool ServerON = false;         public TcpListener ServerL;         public int ServerLoad = 2;         public string ServerINFtxt = '';         public ASCIIEncoding AE = new ASCIIEncoding();          public MainForm()         {             InitializeComponent();         }          private void LBL_SS_Click(object sender, EventArgs e)         {          }          private void MainForm_Load(object sender, EventArgs e)         {             LBL_SS.ForeColor = Color.Red;         }          public void AddH(string S)         {             ServerINFtxt += S;         }          public void Server()         {             try             {                 ServerL = new TcpListener(47);                 ServerL.Start();                 AddH('\nServer Started On Port 47');             }             catch(Exception e)             {                 MessageBox.Show('Error starting Server.__________________\n'+e.ToString());             }             while (true)             {                 TcpClient TCPC;                 TCPC = ServerL.AcceptTcpClient();                 if (ServerLoad < 100)                 {                     Thread T = new Thread(HandleClient);                     T.Start((object)TCPC);                 }                 else                 {                     byte[] BYTES = AE.GetBytes('NoAccess:Full');                     NetworkStream NS = TCPC.GetStream();                     NS.Write(BYTES, 0, BYTES.Length);                 }             }         }          public void HandleClient(object C)         {             ServerLoad++;             TcpClient Client = (TcpClient)C;             NetworkStream NS = Client.GetStream();             AddH('Client Connected.\nServer Load: ' + ServerLoad);             Thread T = new Thread(ReadClient);             T.Start(C);             try             {                 while (true) { NS.Write(AE.GetBytes(''), 0, AE.GetBytes('').Length); }             }             catch { }             ServerLoad--;             AddH('Client Disconnected.\nServer Load: ' + ServerLoad);         }          public void ReadClient(object C)         {             //TcpClient Client = (TcpClient)C;         }          private void startStopToolStripMenuItem_Click(object sender, EventArgs e)         {                 LBL_SS.Text = 'Server On';                 LBL_SS.ForeColor = Color.Green;                 if (ServerON == false)                 {                     Thread T = new Thread(Server);                     T.Start();                 }                 ServerON = true;         }          private void Update_Tick(object sender, EventArgs e)         {             ServerINF.Text = ServerINFtxt;             PB_SL.Value = ServerLoad;         }     } } 
  • 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. 2026-05-10T23:57:12+00:00Added an answer on May 10, 2026 at 11:57 pm

    If you make a blocking call to read on a network stream and it returns 0 bytes as the length that it read it means that your client has disconnected. You will not get an exception until you try write to this connection. That’s my best guess as to what is happening.

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

Sidebar

Ask A Question

Stats

  • Questions 145k
  • Answers 145k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is stated on http://mono-project.com/MonoTouch_Beta that you have to fill… May 12, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer This seems like a very odd design approach. In general… May 12, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer To exclude any number of fields from binding just list… May 12, 2026 at 8:53 am

Related Questions

Hopefully someone can shed a little light on an issue that I'm currently having
Ok, this has got to be a super simple problem. I just can't seem
I have a problem which is most likely a simple problem, but neverthe less
Ok, I'm programming in objective-C and using Xcode. I have read through the documentation

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.