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

Related Questions

I have a simple problem when querying the SQL Server 2005 database. I have
here's my probably (and hopefully) simple problem: i have a list with images as
I have a very simple problem which requires a very quick and simple solution
Seems like a simple problem: I have an SVN repo inside our firewall. I
I have a very simple problem and a solution that will work, but I'm
i have very simple problem. I need to create model, that represent element of
I have a seemingly simple problem though i am unable to get my head
I am sure this is a very simple problem, but I am new to
This may be a very simple problem, but I couldn't find an answer googleing
Today we faced a quite simple problem that were made even simpler by the

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.