Re: how TcpLinstenr is fired in windows service

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



This exception occurs when you want to listen on the address:port that are
already used by other application.

use netstat -an -p tcp to determine what addresses:ports are occupied.
Normaly only one socket can listen on particular port.

In order to listen on the address already occupied by someone else - you can
set socket option
SocketOptionName.ReuseAddress

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"TulasiKumar" <tulasikumar@xxxxxxxxxxxxxxxxxx> wrote in message
news:OaqvHDREGHA.336@xxxxxxxxxxxxxxxxxxxxxxx
>
> Hi Vadyam Stetsyak,
> Thank u for giving immediate response.
> The above code raise one exception In listner method TcpListner.start()
> there raises one exception.The Exception name is "Only One usage of each
> socket address(protocol/network Address/Port)is normally permitted"This
> exception raised.
> Give me ur suggestion
> thanks in advance,
> Regards,
> TulasiKumar
> "Vadym Stetsyak" <vadym_s@xxxxxxx> wrote in message
> news:%23hUCWLQEGHA.644@xxxxxxxxxxxxxxxxxxxxxxx
> > Are there any exceptions in this code?
> > what is url parameter, can it be that url will specify remote server?
> >
> > --
> > Vadym Stetsyak aka Vadmyst
> > http://vadmyst.blogspot.com
> >
> > "TulasiKumar" <tulasikumar@xxxxxxxxxxxxxxxxxx> wrote in message
> > news:eZFJ4rPEGHA.1120@xxxxxxxxxxxxxxxxxxxxxxx
> > > Hi all,
> > >
> > > What is my requirement is i want to get the TCPIP data from TCP
> Port.I
> had
> > > written the code in c#.Net.What i had written the code is pasted
> > > below.what
> > > i written the code is correct or not according to my
> requirement.Using
> > > this
> > > code i didn't get any TCPIP pcakects data.Any one can modify my code
> or my
> > > way of approach is wrong,please tell me.
> > >
> > > Your suggestions ar kindly accepted.
> > >
> > > Thanks in advance.
> > >
> > > public class TcpData
> > >
> > > {
> > >
> > > private TcpListener tcpListener;
> > >
> > > private int Port;
> > >
> > > private string UrlStr;
> > >
> > > // private StringCollection quotes;
> > >
> > > // private Random random;
> > >
> > > private Thread listenerThread;
> > >
> > > private TcpClient tcpClient;
> > >
> > > private NetworkStream netStream;
> > >
> > > public TcpData()
> > >
> > > {
> > >
> > > //
> > >
> > > // TODO: Add constructor logic here
> > >
> > > //
> > >
> > > }
> > >
> > > public TcpData(String Url,int port)
> > >
> > > {
> > >
> > > this.UrlStr=Url;
> > >
> > > this.Port=port;
> > >
> > > }
> > >
> > > public void Start()
> > >
> > > {
> > >
> > > try
> > >
> > > {
> > >
> > > listenerThread=new Thread(new ThreadStart(this.Listener));
> > >
> > > listenerThread.Start();
> > >
> > > }
> > >
> > > catch(Exception ex)
> > >
> > > {
> > >
> > > Console.WriteLine(ex.Message);
> > >
> > > }
> > >
> > >
> > >
> > > }
> > >
> > > protected void Listener()
> > >
> > > {
> > >
> > > try
> > >
> > > {
> > >
> > > FileInfo fs=new FileInfo("StreamData.txt");
> > >
> > >
> > > StreamWriter swr=new StreamWriter("StreamData.txt",true);
> > >
> > > IPAddress ipAddress=Dns.Resolve(UrlStr).AddressList[0];
> > >
> > > tcpListener=new TcpListener(ipAddress,Port);
> > >
> > > tcpListener.Start();
> > >
> > > while(true)
> > >
> > > {
> > >
> > > tcpClient=tcpListener.AcceptTcpClient();
> > >
> > > netStream=tcpClient.GetStream();
> > >
> > > if(netStream.CanRead)
> > >
> > > {
> > >
> > > // Reads NetworkStream into a byte buffer.
> > >
> > > byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
> > >
> > > // Read can return anything from 0 to numBytesToRead.
> > >
> > > // This method blocks until at least one byte is read.
> > >
> > > netStream.Read (bytes, 0, (int)tcpClient.ReceiveBufferSize);
> > >
> > > // Returns the data received from the host to the console.
> > >
> > > string returndata = Encoding.UTF8.GetString (bytes);
> > >
> > > Console.WriteLine ("This is what the host returned to you: " +
> > >
> > > returndata);
> > >
> > > swr.WriteLine(returndata);
> > >
> > >
> > >
> > >
> > > }
> > >
> > > else
> > >
> > > {
> > >
> > > Console.WriteLine ("You cannot read data from this stream.");
> > >
> > > tcpClient.Close ();
> > >
> > > // Closing the tcpClient instance does not close the network stream.
> > >
> > >
> > > //return;
> > >
> > > }
> > >
> > > netStream.Close ();
> > >
> > > swr.Flush();
> > >
> > > swr.Close();
> > >
> > > }
> > >
> > > }
> > >
> > > catch(Exception ex)
> > >
> > > {
> > >
> > > Console.WriteLine(ex.Message);
> > >
> > > }
> > >
> > >
> > > }
> > >
> > >
> > > public void Stop()
> > >
> > > {
> > >
> > > tcpListener.Stop();
> > >
> > > }
> > >
> > > public void Resume()
> > >
> > > {
> > >
> > > listenerThread.Resume();
> > >
> > > }
> > >
> > > public void Suspend()
> > >
> > > {
> > >
> > > listenerThread.Suspend();
> > >
> > > }
> > >
> > > Regards,
> > >
> > > TulasiKumar
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>
>
>


.



Relevant Pages

  • sock = listener.AcceptSocket();
    ... public void CloseListener() ... catch (Exception) ... listener = new TcpListener; ... sock = listener.AcceptSocket; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Yet another generics question: Needs unchecked conversion to conform to ...
    ... This is a surprisingly common generics question, and the answer, incidentally, is "no". ... Consider a pipeline of some kind in which objects are put into a Pipeline object and Pipelines notify their Listeners with these objects, allowing loose coupling and runtime rearrangement of the plumbing. ... public void handleObject; ... public void addListener { ...
    (comp.lang.java.programmer)
  • valueForPathChanged event
    ... model for the tree and display the data in the gui in the form of a ... public void valueForPathChanged{ ... listenerList.addElement(listener); ... (TreeModelListener) ...
    (comp.lang.java.gui)
  • valueForPathChanged event
    ... model for the tree and display the data in the gui in the form of a ... public void valueForPathChanged{ ... listenerList.addElement(listener); ... (TreeModelListener) ...
    (comp.lang.java.programmer)
  • Re: valueForPathChanged event
    ... model for the tree and display the data in the gui in the form of a ... listenerList.addElement(listener); ... public void removeTreeModelListener{ ... (TreeModelListener) ...
    (comp.lang.java.programmer)