Running Network Application on port Server side give me error how can i solve it?

Posted by Phsika on Stack Overflow See other posts from Stack Overflow or by Phsika
Published on 2010-05-08T17:56:48Z Indexed on 2010/05/08 18:08 UTC
Read the original article Hit count: 326

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 Çalisti";
            }
            catch (Exception ex)
            {
                this.Text = "kanal çalismadi";
                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("Indirilme Tarihi=" + DateTime.Now); listBox1.Items.Add("--------------------------------"); } } } } catch (Exception ex) { MessageBox.Show("hata:" + ex.ToString()); } } } }

© Stack Overflow or respective owner

Related posts about c#

Related posts about visual-studio