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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:19:51+00:00 2026-05-14T19:19:51+00:00

if i run Server App. Exception occurs: on Dinle.Start() System.Net.SocketException – Only one usage

  • 0

if i run Server App. Exception occurs: on Dinle.Start()

System.Net.SocketException – Only one usage of each socket address (protocol/network address/port) is normally permitted

How can i solve this error?

alt text

Server.cs

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.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace Server
{
    public partial class Server : Form
    {
        Thread kanal;
        public Server()
        {
            InitializeComponent();

            try
            {
                kanal = new Thread(new ThreadStart(Dinle));
                kanal.Start();
                kanal.Priority = ThreadPriority.Normal;
                this.Text = "Kanla Çalıştı";
            }
            catch (Exception ex)
            {
                this.Text = "kanal çalışmadı";
                MessageBox.Show("hata:" + ex.ToString());
                kanal.Abort();
                throw;
            }
        }

        private void Server_Load(object sender, EventArgs e)
        {
            Dinle();
        }
        private void btn_Listen_Click(object sender, EventArgs e)
        {

            Dinle();
        }

        void Dinle()
        {
          //  IPAddress localAddr = IPAddress.Parse("localhost");
            // TcpListener server = new TcpListener(port);
           // server = new TcpListener(localAddr, port);
            //TcpListener Dinle = new TcpListener(localAddr,51124);
            TcpListener Dinle = new TcpListener(51124);
            try
            {

                while (true)
                {
                   

Dinle.Start();

Exception is occured. Socket Baglanti = Dinle.AcceptSocket(); if (!Baglanti.Connected) { MessageBox.Show("Baglanti Yok"); } else { TcpClient tcpClient = Dinle.AcceptTcpClient(); if (tcpClient.ReceiveBufferSize > 0) { byte[] Dizi = new byte[250000]; Baglanti.Receive(Dizi, Dizi.Length, 0); string Yol; saveFileDialog1.Title = "Dosyayi kaydet"; saveFileDialog1.ShowDialog(); Yol = saveFileDialog1.FileName; FileStream Dosya = new FileStream(Yol, FileMode.Create); Dosya.Write(Dizi, 0, Dizi.Length - 20); Dosya.Close(); listBox1.Items.Add("dosya indirildi"); listBox1.Items.Add("Dosya Boyutu=" + Dizi.Length.ToString()); listBox1.Items.Add("İndirilme Tarihi=" + DateTime.Now); listBox1.Items.Add("--------------------------------"); } } } } catch (Exception ex) { MessageBox.Show("hata:" + ex.ToString()); } } } }
  • 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-14T19:19:52+00:00Added an answer on May 14, 2026 at 7:19 pm

    TcpListener.Start is being called multiple times.

    1- Called when you start your thread in the Server constructor
    2- Via the call to Dinle in the Server_Load event handler
    3- Again if you click the button in the btn_Listen_Click event handler

    I do not claim to have a complete grasp of what you are trying to do but I think this can be simplified.

    First you should create and start the listener once, lets say when the code starts running. After that you can enter into a loop that calls AcceptTcpClient to accept connection and handle the communication.

    You also seem to be mixing Socket and TcpClient which should not be needed. Take a look at the following like for a basic example of using TcpListener and TcpClient.

    http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From Install Curl Extension for PHP in Ubuntu: sudo apt-get… May 15, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer For large operations like this it is better to go… May 15, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer I don't think there's anything inherently wrong with this. We… May 15, 2026 at 1:15 am

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.