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 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 67k
  • Answers 67k
  • 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
  • added an answer Synchronization is very easy in Windows Forms. You can call… May 11, 2026 at 11:51 am
  • added an answer The obvious interpretation is that executing the same image on… May 11, 2026 at 11:51 am
  • added an answer Distutils use sys.gettotalrefcount to detect a debug python build: #… May 11, 2026 at 11:51 am

Related Questions

Ok, simple problem hopefully. I have started to make a simple server for a
Ok, this has got to be a super simple problem. I just can't seem
Ok, I had a simple layout problem a week or two ago. Namely sections
Ok, i have simple scenario: have two pages: login and welcome pages. im using
Ok, this probably has a really simple answer, but I've never tried to do
Ok, so I have a very simple form with next to no logic in
Ok, this is possibly borderline-subjective, but I wonder where one would put a simple
Simple code: >>> set([2,2,1,2,2,2,3,3,5,1]) set([1, 2, 3, 5]) Ok, in the resulting sets there
OK. This is a bit of a vanity app, but I had a situation
OK, I know what you're thinking, "why write a method you do not want

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.