473,781 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how TcpLinstenr is fired in windows service

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.Usi ng 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 StringCollectio n 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(thi s.Listener));

listenerThread. Start();

}

catch(Exception ex)

{

Console.WriteLi ne(ex.Message);

}

}

protected void Listener()

{

try

{

FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);

IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];

tcpListener=new TcpListener(ipA ddress,Port);

tcpListener.Sta rt();

while(true)

{

tcpClient=tcpLi stener.AcceptTc pClient();

netStream=tcpCl ient.GetStream( );

if(netStream.Ca nRead)

{

// Reads NetworkStream into a byte buffer.

byte[] bytes = new byte[tcpClient.Recei veBufferSize];

// Read can return anything from 0 to numBytesToRead.

// This method blocks until at least one byte is read.

netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);

// Returns the data received from the host to the console.

string returndata = Encoding.UTF8.G etString (bytes);

Console.WriteLi ne ("This is what the host returned to you: " +

returndata);

swr.WriteLine(r eturndata);


}

else

{

Console.WriteLi ne ("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.WriteLi ne(ex.Message);

}
}
public void Stop()

{

tcpListener.Sto p();

}

public void Resume()

{

listenerThread. Resume();

}

public void Suspend()

{

listenerThread. Suspend();

}

Regards,

TulasiKumar

Jan 4 '06 #1
9 1496
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

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
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.Usi ng
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 StringCollectio n 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(thi s.Listener));

listenerThread. Start();

}

catch(Exception ex)

{

Console.WriteLi ne(ex.Message);

}

}

protected void Listener()

{

try

{

FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);

IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];

tcpListener=new TcpListener(ipA ddress,Port);

tcpListener.Sta rt();

while(true)

{

tcpClient=tcpLi stener.AcceptTc pClient();

netStream=tcpCl ient.GetStream( );

if(netStream.Ca nRead)

{

// Reads NetworkStream into a byte buffer.

byte[] bytes = new byte[tcpClient.Recei veBufferSize];

// Read can return anything from 0 to numBytesToRead.

// This method blocks until at least one byte is read.

netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);

// Returns the data received from the host to the console.

string returndata = Encoding.UTF8.G etString (bytes);

Console.WriteLi ne ("This is what the host returned to you: " +

returndata);

swr.WriteLine(r eturndata);


}

else

{

Console.WriteLi ne ("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.WriteLi ne(ex.Message);

}
}
public void Stop()

{

tcpListener.Sto p();

}

public void Resume()

{

listenerThread. Resume();

}

public void Suspend()

{

listenerThread. Suspend();

}

Regards,

TulasiKumar


Jan 4 '06 #2

Hi Vadyam Stetsyak,
Thank u for giving immediate response.
The above code raise one exception In listner method TcpListner.star t()
there raises one exception.The Exception name is "Only One usage of each
socket address(protoco l/network Address/Port)is normally permitted"This
exception raised.
Give me ur suggestion
thanks in advance,
Regards,
TulasiKumar
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
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

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
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.Usi ng
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 StringCollectio n 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(thi s.Listener));

listenerThread. Start();

}

catch(Exception ex)

{

Console.WriteLi ne(ex.Message);

}

}

protected void Listener()

{

try

{

FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);

IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];

tcpListener=new TcpListener(ipA ddress,Port);

tcpListener.Sta rt();

while(true)

{

tcpClient=tcpLi stener.AcceptTc pClient();

netStream=tcpCl ient.GetStream( );

if(netStream.Ca nRead)

{

// Reads NetworkStream into a byte buffer.

byte[] bytes = new byte[tcpClient.Recei veBufferSize];

// Read can return anything from 0 to numBytesToRead.

// This method blocks until at least one byte is read.

netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);

// Returns the data received from the host to the console.

string returndata = Encoding.UTF8.G etString (bytes);

Console.WriteLi ne ("This is what the host returned to you: " +

returndata);

swr.WriteLine(r eturndata);


}

else

{

Console.WriteLi ne ("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.WriteLi ne(ex.Message);

}
}
public void Stop()

{

tcpListener.Sto p();

}

public void Resume()

{

listenerThread. Resume();

}

public void Suspend()

{

listenerThread. Suspend();

}

Regards,

TulasiKumar





Jan 4 '06 #3
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
SocketOptionNam e.ReuseAddress

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

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:Oa******** *****@TK2MSFTNG P14.phx.gbl...

Hi Vadyam Stetsyak,
Thank u for giving immediate response.
The above code raise one exception In listner method TcpListner.star t()
there raises one exception.The Exception name is "Only One usage of each
socket address(protoco l/network Address/Port)is normally permitted"This
exception raised.
Give me ur suggestion
thanks in advance,
Regards,
TulasiKumar
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> 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
>
> "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
> > 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.Usi ng > > 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 StringCollectio n 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(thi s.Listener));
> >
> > listenerThread. Start();
> >
> > }
> >
> > catch(Exception ex)
> >
> > {
> >
> > Console.WriteLi ne(ex.Message);
> >
> > }
> >
> >
> >
> > }
> >
> > protected void Listener()
> >
> > {
> >
> > try
> >
> > {
> >
> > FileInfo fs=new FileInfo("Strea mData.txt");
> >
> >
> > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> >
> > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> >
> > tcpListener=new TcpListener(ipA ddress,Port);
> >
> > tcpListener.Sta rt();
> >
> > while(true)
> >
> > {
> >
> > tcpClient=tcpLi stener.AcceptTc pClient();
> >
> > netStream=tcpCl ient.GetStream( );
> >
> > if(netStream.Ca nRead)
> >
> > {
> >
> > // Reads NetworkStream into a byte buffer.
> >
> > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> >
> > // Read can return anything from 0 to numBytesToRead.
> >
> > // This method blocks until at least one byte is read.
> >
> > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
> >
> > // Returns the data received from the host to the console.
> >
> > string returndata = Encoding.UTF8.G etString (bytes);
> >
> > Console.WriteLi ne ("This is what the host returned to you: " +
> >
> > returndata);
> >
> > swr.WriteLine(r eturndata);
> >
> >
> >
> >
> > }
> >
> > else
> >
> > {
> >
> > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> >
> > }
> >
> >
> > }
> >
> >
> > public void Stop()
> >
> > {
> >
> > tcpListener.Sto p();
> >
> > }
> >
> > public void Resume()
> >
> > {
> >
> > listenerThread. Resume();
> >
> > }
> >
> > public void Suspend()
> >
> > {
> >
> > listenerThread. Suspend();
> >
> > }
> >
> > Regards,
> >
> > TulasiKumar
> >
> >
> >
> >
> >

>
>


Jan 4 '06 #4

Hi VadyamStetsyak,
Thank u very much for giving immediate response.
SocketOptionNam e.ReuseAddress
Where can i inclue the above statment in my program.i have tried but ,it
is given the error.Can u please modify the below code or can u tell me where
can i include the above statement.Pleas e tell me.This is very urgent.

Thanks in advance,
public class TcpData
{

private TcpListener tcpListener;

private int Port;
private string UrlStr;
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(thi s.Listener));
listenerThread. Start();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
}
protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

tcpListener.Sta rt();
while(true)
{
tcpClient=tcpLi stener.AcceptTc pClient();
netStream=tcpCl ient.GetStream( );
if(netStream.Ca nRead)
{
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.Recei veBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
// Returns the data received from the host to the console.
string returndata = Encoding.UTF8.G etString (bytes);
Console.WriteLi ne ("This is what the host returned to you: " +
returndata);
swr.WriteLine(r eturndata);
}
else
{
Console.WriteLi ne ("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.WriteLi ne(ex.Message);
}
}
public void Stop()
{
tcpListener.Sto p();
}
public void Resume()
{
listenerThread. Resume();
}
public void Suspend()
{
listenerThread. Suspend();
}
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:uE******** ******@TK2MSFTN GP11.phx.gbl...
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
SocketOptionNam e.ReuseAddress

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

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:Oa******** *****@TK2MSFTNG P14.phx.gbl...

Hi Vadyam Stetsyak,
Thank u for giving immediate response.
The above code raise one exception In listner method TcpListner.star t() there raises one exception.The Exception name is "Only One usage of each socket address(protoco l/network Address/Port)is normally permitted"This exception raised.
Give me ur suggestion
thanks in advance,
Regards,
TulasiKumar
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> 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
>
> "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
> > 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.Usi ng
> > 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 StringCollectio n 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(thi s.Listener));
> >
> > listenerThread. Start();
> >
> > }
> >
> > catch(Exception ex)
> >
> > {
> >
> > Console.WriteLi ne(ex.Message);
> >
> > }
> >
> >
> >
> > }
> >
> > protected void Listener()
> >
> > {
> >
> > try
> >
> > {
> >
> > FileInfo fs=new FileInfo("Strea mData.txt");
> >
> >
> > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> >
> > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> >
> > tcpListener=new TcpListener(ipA ddress,Port);
> >
> > tcpListener.Sta rt();
> >
> > while(true)
> >
> > {
> >
> > tcpClient=tcpLi stener.AcceptTc pClient();
> >
> > netStream=tcpCl ient.GetStream( );
> >
> > if(netStream.Ca nRead)
> >
> > {
> >
> > // Reads NetworkStream into a byte buffer.
> >
> > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> >
> > // Read can return anything from 0 to numBytesToRead.
> >
> > // This method blocks until at least one byte is read.
> >
> > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
> >
> > // Returns the data received from the host to the console.
> >
> > string returndata = Encoding.UTF8.G etString (bytes);
> >
> > Console.WriteLi ne ("This is what the host returned to you: " +
> >
> > returndata);
> >
> > swr.WriteLine(r eturndata);
> >
> >
> >
> >
> > }
> >
> > else
> >
> > {
> >
> > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> >
> > }
> >
> >
> > }
> >
> >
> > public void Stop()
> >
> > {
> >
> > tcpListener.Sto p();
> >
> > }
> >
> > public void Resume()
> >
> > {
> >
> > listenerThread. Resume();
> >
> > }
> >
> > public void Suspend()
> >
> > {
> >
> > listenerThread. Suspend();
> >
> > }
> >
> > Regards,
> >
> > TulasiKumar
> >
> >
> >
> >
> >
>
>





Jan 4 '06 #5
to set the option you have to use

Socket.SetSocke tOption(SocketO ptionLevel.Sock et,
SocketOptionNam e.ReuseAddress, 1);

protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

//------------
tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
SocketOptionNam e.ReuseAddress, 1);
//------------

tcpListener.Sta rt();
--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...

Hi VadyamStetsyak,
Thank u very much for giving immediate response.
SocketOptionNam e.ReuseAddress
Where can i inclue the above statment in my program.i have tried but ,it
is given the error.Can u please modify the below code or can u tell me
where
can i include the above statement.Pleas e tell me.This is very urgent.

Thanks in advance,
public class TcpData
{

private TcpListener tcpListener;

private int Port;
private string UrlStr;
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(thi s.Listener));
listenerThread. Start();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
}
protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

tcpListener.Sta rt();
while(true)
{
tcpClient=tcpLi stener.AcceptTc pClient();
netStream=tcpCl ient.GetStream( );
if(netStream.Ca nRead)
{
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.Recei veBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
// Returns the data received from the host to the console.
string returndata = Encoding.UTF8.G etString (bytes);
Console.WriteLi ne ("This is what the host returned to you: " +
returndata);
swr.WriteLine(r eturndata);
}
else
{
Console.WriteLi ne ("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.WriteLi ne(ex.Message);
}
}
public void Stop()
{
tcpListener.Sto p();
}
public void Resume()
{
listenerThread. Resume();
}
public void Suspend()
{
listenerThread. Suspend();
}
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:uE******** ******@TK2MSFTN GP11.phx.gbl...
> 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
> SocketOptionNam e.ReuseAddress
>
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> news:Oa******** *****@TK2MSFTNG P14.phx.gbl...
> >
> > Hi Vadyam Stetsyak,
> > Thank u for giving immediate response.
> > The above code raise one exception In listner method TcpListner.star t() > > there raises one exception.The Exception name is "Only One usage of each > > socket address(protoco l/network Address/Port)is normally permitted"This > > exception raised.
> > Give me ur suggestion
> > thanks in advance,
> > Regards,
> > TulasiKumar
> > "Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
> > news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> > > 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
> > >
> > > "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> > > news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
> > > > 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.Usi ng
> > > > 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 StringCollectio n 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(thi s.Listener));
> > > >
> > > > listenerThread. Start();
> > > >
> > > > }
> > > >
> > > > catch(Exception ex)
> > > >
> > > > {
> > > >
> > > > Console.WriteLi ne(ex.Message);
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > }
> > > >
> > > > protected void Listener()
> > > >
> > > > {
> > > >
> > > > try
> > > >
> > > > {
> > > >
> > > > FileInfo fs=new FileInfo("Strea mData.txt");
> > > >
> > > >
> > > > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> > > >
> > > > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> > > >
> > > > tcpListener=new TcpListener(ipA ddress,Port);
> > > >
> > > > tcpListener.Sta rt();
> > > >
> > > > while(true)
> > > >
> > > > {
> > > >
> > > > tcpClient=tcpLi stener.AcceptTc pClient();
> > > >
> > > > netStream=tcpCl ient.GetStream( );
> > > >
> > > > if(netStream.Ca nRead)
> > > >
> > > > {
> > > >
> > > > // Reads NetworkStream into a byte buffer.
> > > >
> > > > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> > > >
> > > > // Read can return anything from 0 to numBytesToRead.
> > > >
> > > > // This method blocks until at least one byte is read.
> > > >
> > > > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
> > > >
> > > > // Returns the data received from the host to the console.
> > > >
> > > > string returndata = Encoding.UTF8.G etString (bytes);
> > > >
> > > > Console.WriteLi ne ("This is what the host returned to you: " +
> > > >
> > > > returndata);
> > > >
> > > > swr.WriteLine(r eturndata);
> > > >
> > > >
> > > >
> > > >
> > > > }
> > > >
> > > > else
> > > >
> > > > {
> > > >
> > > > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> > > >
> > > > }
> > > >
> > > >
> > > > }
> > > >
> > > >
> > > > public void Stop()
> > > >
> > > > {
> > > >
> > > > tcpListener.Sto p();
> > > >
> > > > }
> > > >
> > > > public void Resume()
> > > >
> > > > {
> > > >
> > > > listenerThread. Resume();
> > > >
> > > > }
> > > >
> > > > public void Suspend()
> > > >
> > > > {
> > > >
> > > > listenerThread. Suspend();
> > > >
> > > > }
> > > >
> > > > Regards,
> > > >
> > > > TulasiKumar
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> >

>
>


Jan 4 '06 #6
Hi Vadym Stetsyak,
Thanks for giving immediate response.

Whenever i have pasted u have given code as follows
protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

//------------
tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
SocketOptionNam e.ReuseAddress, 1);
//------------

tcpListener.Sta rt();

it is getting the below error.This is given some protection level
errorr.Please tell me will i import any name space?. or i am doing any
think worng.
I have imported two main name sapces
using System.Net;

using System.Net.Sock ets;

this is the error:'System.N et.Sockets.TcpL istener.Server' is inaccessible
due to its protection level

"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
to set the option you have to use

Socket.SetSocke tOption(SocketO ptionLevel.Sock et,
SocketOptionNam e.ReuseAddress, 1);

protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

//------------
tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
SocketOptionNam e.ReuseAddress, 1);
//------------

tcpListener.Sta rt();
--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...

Hi VadyamStetsyak,
Thank u very much for giving immediate response.
SocketOptionNam e.ReuseAddress
Where can i inclue the above statment in my program.i have tried but ,it is given the error.Can u please modify the below code or can u tell me
where
can i include the above statement.Pleas e tell me.This is very urgent.

Thanks in advance,
public class TcpData
{

private TcpListener tcpListener;

private int Port;
private string UrlStr;
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(thi s.Listener));
listenerThread. Start();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
}
protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

tcpListener.Sta rt();
while(true)
{
tcpClient=tcpLi stener.AcceptTc pClient();
netStream=tcpCl ient.GetStream( );
if(netStream.Ca nRead)
{
// Reads NetworkStream into a byte buffer.
byte[] bytes = new byte[tcpClient.Recei veBufferSize];
// Read can return anything from 0 to numBytesToRead.
// This method blocks until at least one byte is read.
netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
// Returns the data received from the host to the console.
string returndata = Encoding.UTF8.G etString (bytes);
Console.WriteLi ne ("This is what the host returned to you: " +
returndata);
swr.WriteLine(r eturndata);
}
else
{
Console.WriteLi ne ("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.WriteLi ne(ex.Message);
}
}
public void Stop()
{
tcpListener.Sto p();
}
public void Resume()
{
listenerThread. Resume();
}
public void Suspend()
{
listenerThread. Suspend();
}
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:uE******** ******@TK2MSFTN GP11.phx.gbl...
> 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
> SocketOptionNam e.ReuseAddress
>
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> news:Oa******** *****@TK2MSFTNG P14.phx.gbl...
> >
> > Hi Vadyam Stetsyak,
> > Thank u for giving immediate response.
> > The above code raise one exception In listner method

TcpListner.star t()
> > there raises one exception.The Exception name is "Only One usage
of each
> > socket address(protoco l/network Address/Port)is normally

permitted"This
> > exception raised.
> > Give me ur suggestion
> > thanks in advance,
> > Regards,
> > TulasiKumar
> > "Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
> > news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> > > 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
> > >
> > > "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in
message > > > news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
> > > > 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.Usi ng
> > > > 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 StringCollectio n 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(thi s.Listener));
> > > >
> > > > listenerThread. Start();
> > > >
> > > > }
> > > >
> > > > catch(Exception ex)
> > > >
> > > > {
> > > >
> > > > Console.WriteLi ne(ex.Message);
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > }
> > > >
> > > > protected void Listener()
> > > >
> > > > {
> > > >
> > > > try
> > > >
> > > > {
> > > >
> > > > FileInfo fs=new FileInfo("Strea mData.txt");
> > > >
> > > >
> > > > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> > > >
> > > > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> > > >
> > > > tcpListener=new TcpListener(ipA ddress,Port);
> > > >
> > > > tcpListener.Sta rt();
> > > >
> > > > while(true)
> > > >
> > > > {
> > > >
> > > > tcpClient=tcpLi stener.AcceptTc pClient();
> > > >
> > > > netStream=tcpCl ient.GetStream( );
> > > >
> > > > if(netStream.Ca nRead)
> > > >
> > > > {
> > > >
> > > > // Reads NetworkStream into a byte buffer.
> > > >
> > > > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> > > >
> > > > // Read can return anything from 0 to numBytesToRead.
> > > >
> > > > // This method blocks until at least one byte is read.
> > > >
> > > > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
> > > >
> > > > // Returns the data received from the host to the console.
> > > >
> > > > string returndata = Encoding.UTF8.G etString (bytes);
> > > >
> > > > Console.WriteLi ne ("This is what the host returned to you: "

+ > > > >
> > > > returndata);
> > > >
> > > > swr.WriteLine(r eturndata);
> > > >
> > > >
> > > >
> > > >
> > > > }
> > > >
> > > > else
> > > >
> > > > {
> > > >
> > > > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> > > >
> > > > }
> > > >
> > > >
> > > > }
> > > >
> > > >
> > > > public void Stop()
> > > >
> > > > {
> > > >
> > > > tcpListener.Sto p();
> > > >
> > > > }
> > > >
> > > > public void Resume()
> > > >
> > > > {
> > > >
> > > > listenerThread. Resume();
> > > >
> > > > }
> > > >
> > > > public void Suspend()
> > > >
> > > > {
> > > >
> > > > listenerThread. Suspend();
> > > >
> > > > }
> > > >
> > > > Regards,
> > > >
> > > > TulasiKumar
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> >
>
>





Jan 5 '06 #7
what version of .NET framework do you use? I have 2.0 and TclListener.Ser ver
property is public there.
AFAIR in .NET 1.1. it is protected that is you have to inherit from
TcpListener, and then you will get the access you need

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

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:es******** ******@TK2MSFTN GP15.phx.gbl...
Hi Vadym Stetsyak,
Thanks for giving immediate response.

Whenever i have pasted u have given code as follows
protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

//------------
tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
SocketOptionNam e.ReuseAddress, 1);
//------------

tcpListener.Sta rt();

it is getting the below error.This is given some protection level
errorr.Please tell me will i import any name space?. or i am doing any
think worng.
I have imported two main name sapces
using System.Net;

using System.Net.Sock ets;

this is the error:'System.N et.Sockets.TcpL istener.Server' is inaccessible
due to its protection level

"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> to set the option you have to use
>
> Socket.SetSocke tOption(SocketO ptionLevel.Sock et,
> SocketOptionNam e.ReuseAddress, 1);
>
> protected void Listener()
> {
> try
> {
> FileInfo fs=new FileInfo("Strea mData.txt");
> StreamWriter swr=new StreamWriter("S treamData.txt", true);
> IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> tcpListener=new TcpListener(ipA ddress,Port);
>
> //------------
> tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
> SocketOptionNam e.ReuseAddress, 1);
> //------------
>
> tcpListener.Sta rt();
>
>
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> news:u6******** ******@TK2MSFTN GP10.phx.gbl...
> >
> > Hi VadyamStetsyak,
> > Thank u very much for giving immediate response.
> > SocketOptionNam e.ReuseAddress
> > Where can i inclue the above statment in my program.i have tried but ,it > > is given the error.Can u please modify the below code or can u tell me > > where
> > can i include the above statement.Pleas e tell me.This is very urgent.
> >
> > Thanks in advance,
> >
> >
> > public class TcpData
> > {
> >
> > private TcpListener tcpListener;
> >
> > private int Port;
> > private string UrlStr;
> > 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(thi s.Listener));
> > listenerThread. Start();
> > }
> > catch(Exception ex)
> > {
> > Console.WriteLi ne(ex.Message);
> > }
> > }
> > protected void Listener()
> > {
> > try
> > {
> > FileInfo fs=new FileInfo("Strea mData.txt");
> > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> > tcpListener=new TcpListener(ipA ddress,Port);
> >
> > tcpListener.Sta rt();
> > while(true)
> > {
> > tcpClient=tcpLi stener.AcceptTc pClient();
> > netStream=tcpCl ient.GetStream( );
> > if(netStream.Ca nRead)
> > {
> > // Reads NetworkStream into a byte buffer.
> > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> > // Read can return anything from 0 to numBytesToRead.
> > // This method blocks until at least one byte is read.
> > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
> > // Returns the data received from the host to the console.
> > string returndata = Encoding.UTF8.G etString (bytes);
> > Console.WriteLi ne ("This is what the host returned to you: " +
> > returndata);
> > swr.WriteLine(r eturndata);
> > }
> > else
> > {
> > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> > }
> > }
> > public void Stop()
> > {
> > tcpListener.Sto p();
> > }
> > public void Resume()
> > {
> > listenerThread. Resume();
> > }
> > public void Suspend()
> > {
> > listenerThread. Suspend();
> > }
> >
> >
> > "Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
> > news:uE******** ******@TK2MSFTN GP11.phx.gbl...
> > > 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
> > > SocketOptionNam e.ReuseAddress
> > >
> > > --
> > > Vadym Stetsyak aka Vadmyst
> > > http://vadmyst.blogspot.com
> > >
> > > "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> > > news:Oa******** *****@TK2MSFTNG P14.phx.gbl...
> > > >
> > > > Hi Vadyam Stetsyak,
> > > > Thank u for giving immediate response.
> > > > The above code raise one exception In listner method
> > TcpListner.star t()
> > > > there raises one exception.The Exception name is "Only One usage of > > each
> > > > socket address(protoco l/network Address/Port)is normally
> > permitted"This
> > > > exception raised.
> > > > Give me ur suggestion
> > > > thanks in advance,
> > > > Regards,
> > > > TulasiKumar
> > > > "Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
> > > > news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> > > > > 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
> > > > >
> > > > > "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message > > > > > news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
> > > > > > 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.Usi ng
> > > > > > 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 StringCollectio n 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(thi s.Listener));
> > > > > >
> > > > > > listenerThread. Start();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > catch(Exception ex)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > Console.WriteLi ne(ex.Message);
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > > protected void Listener()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > try
> > > > > >
> > > > > > {
> > > > > >
> > > > > > FileInfo fs=new FileInfo("Strea mData.txt");
> > > > > >
> > > > > >
> > > > > > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> > > > > >
> > > > > > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> > > > > >
> > > > > > tcpListener=new TcpListener(ipA ddress,Port);
> > > > > >
> > > > > > tcpListener.Sta rt();
> > > > > >
> > > > > > while(true)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > tcpClient=tcpLi stener.AcceptTc pClient();
> > > > > >
> > > > > > netStream=tcpCl ient.GetStream( );
> > > > > >
> > > > > > if(netStream.Ca nRead)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > // Reads NetworkStream into a byte buffer.
> > > > > >
> > > > > > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> > > > > >
> > > > > > // Read can return anything from 0 to numBytesToRead.
> > > > > >
> > > > > > // This method blocks until at least one byte is read.
> > > > > >
> > > > > > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze); > > > > > >
> > > > > > // Returns the data received from the host to the console.
> > > > > >
> > > > > > string returndata = Encoding.UTF8.G etString (bytes);
> > > > > >
> > > > > > Console.WriteLi ne ("This is what the host returned to you: "
+ > > > > > >
> > > > > > returndata);
> > > > > >
> > > > > > swr.WriteLine(r eturndata);
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > > else
> > > > > >
> > > > > > {
> > > > > >
> > > > > > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > > public void Stop()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > tcpListener.Sto p();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > public void Resume()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > listenerThread. Resume();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > public void Suspend()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > listenerThread. Suspend();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > Regards,
> > > > > >
> > > > > > TulasiKumar
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> >

>
>


Jan 5 '06 #8
hi,
thank u very much for giving information
i am using .net framwork1.1.In framwork 1.1 TcpListner.Serv er property is
protected.So,i have inherited the The TcpListner class in to my class it is
getting one error.
class Tcp1:TcpListene r

{

public Tcp1(int x)

{

Server.SetSocke tOption(SocketO ptionLevel.Sock et,SocketOption Name.ReuseAddre s
s, 1);

}

}

Error:No overload for method 'TcpListener' takes '0' arguments
Thanks in advance

Regrads,

TulasiKumar
"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:uI******** ******@TK2MSFTN GP14.phx.gbl...
what version of .NET framework do you use? I have 2.0 and TclListener.Ser ver property is public there.
AFAIR in .NET 1.1. it is protected that is you have to inherit from
TcpListener, and then you will get the access you need

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

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:es******** ******@TK2MSFTN GP15.phx.gbl...
Hi Vadym Stetsyak,
Thanks for giving immediate response.

Whenever i have pasted u have given code as follows
protected void Listener()
{
try
{
FileInfo fs=new FileInfo("Strea mData.txt");
StreamWriter swr=new StreamWriter("S treamData.txt", true);
IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
tcpListener=new TcpListener(ipA ddress,Port);

//------------
tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
SocketOptionNam e.ReuseAddress, 1);
//------------

tcpListener.Sta rt();

it is getting the below error.This is given some protection level
errorr.Please tell me will i import any name space?. or i am doing any think worng.
I have imported two main name sapces
using System.Net;

using System.Net.Sock ets;

this is the error:'System.N et.Sockets.TcpL istener.Server' is inaccessible due to its protection level

"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> to set the option you have to use
>
> Socket.SetSocke tOption(SocketO ptionLevel.Sock et,
> SocketOptionNam e.ReuseAddress, 1);
>
> protected void Listener()
> {
> try
> {
> FileInfo fs=new FileInfo("Strea mData.txt");
> StreamWriter swr=new StreamWriter("S treamData.txt", true);
> IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> tcpListener=new TcpListener(ipA ddress,Port);
>
> //------------
> tcpListener.Ser ver.SetSocketOp tion(SocketOpti onLevel.Socket,
> SocketOptionNam e.ReuseAddress, 1);
> //------------
>
> tcpListener.Sta rt();
>
>
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
> news:u6******** ******@TK2MSFTN GP10.phx.gbl...
> >
> > Hi VadyamStetsyak,
> > Thank u very much for giving immediate response.
> > SocketOptionNam e.ReuseAddress
> > Where can i inclue the above statment in my program.i have tried but
,it
> > is given the error.Can u please modify the below code or can u
tell me
> > where
> > can i include the above statement.Pleas e tell me.This is very
urgent. > >
> > Thanks in advance,
> >
> >
> > public class TcpData
> > {
> >
> > private TcpListener tcpListener;
> >
> > private int Port;
> > private string UrlStr;
> > 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(thi s.Listener));
> > listenerThread. Start();
> > }
> > catch(Exception ex)
> > {
> > Console.WriteLi ne(ex.Message);
> > }
> > }
> > protected void Listener()
> > {
> > try
> > {
> > FileInfo fs=new FileInfo("Strea mData.txt");
> > StreamWriter swr=new StreamWriter("S treamData.txt", true);
> > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> > tcpListener=new TcpListener(ipA ddress,Port);
> >
> > tcpListener.Sta rt();
> > while(true)
> > {
> > tcpClient=tcpLi stener.AcceptTc pClient();
> > netStream=tcpCl ient.GetStream( );
> > if(netStream.Ca nRead)
> > {
> > // Reads NetworkStream into a byte buffer.
> > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> > // Read can return anything from 0 to numBytesToRead.
> > // This method blocks until at least one byte is read.
> > netStream.Read (bytes, 0, (int)tcpClient. ReceiveBufferSi ze);
> > // Returns the data received from the host to the console.
> > string returndata = Encoding.UTF8.G etString (bytes);
> > Console.WriteLi ne ("This is what the host returned to you: " +
> > returndata);
> > swr.WriteLine(r eturndata);
> > }
> > else
> > {
> > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> > }
> > }
> > public void Stop()
> > {
> > tcpListener.Sto p();
> > }
> > public void Resume()
> > {
> > listenerThread. Resume();
> > }
> > public void Suspend()
> > {
> > listenerThread. Suspend();
> > }
> >
> >
> > "Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
> > news:uE******** ******@TK2MSFTN GP11.phx.gbl...
> > > 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
> > > SocketOptionNam e.ReuseAddress
> > >
> > > --
> > > Vadym Stetsyak aka Vadmyst
> > > http://vadmyst.blogspot.com
> > >
> > > "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in
message > > > news:Oa******** *****@TK2MSFTNG P14.phx.gbl...
> > > >
> > > > Hi Vadyam Stetsyak,
> > > > Thank u for giving immediate response.
> > > > The above code raise one exception In listner method
> > TcpListner.star t()
> > > > there raises one exception.The Exception name is "Only One usage of
> > each
> > > > socket address(protoco l/network Address/Port)is normally
> > permitted"This
> > > > exception raised.
> > > > Give me ur suggestion
> > > > thanks in advance,
> > > > Regards,
> > > > TulasiKumar
> > > > "Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
> > > > news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> > > > > 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
> > > > >
> > > > > "TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in

message
> > > > > news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
> > > > > > 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.Usi ng
> > > > > > 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 StringCollectio n 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(thi s.Listener)); > > > > > >
> > > > > > listenerThread. Start();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > catch(Exception ex)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > Console.WriteLi ne(ex.Message);
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > > protected void Listener()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > try
> > > > > >
> > > > > > {
> > > > > >
> > > > > > FileInfo fs=new FileInfo("Strea mData.txt");
> > > > > >
> > > > > >
> > > > > > StreamWriter swr=new StreamWriter("S treamData.txt", true); > > > > > >
> > > > > > IPAddress ipAddress=Dns.R esolve(UrlStr). AddressList[0];
> > > > > >
> > > > > > tcpListener=new TcpListener(ipA ddress,Port);
> > > > > >
> > > > > > tcpListener.Sta rt();
> > > > > >
> > > > > > while(true)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > tcpClient=tcpLi stener.AcceptTc pClient();
> > > > > >
> > > > > > netStream=tcpCl ient.GetStream( );
> > > > > >
> > > > > > if(netStream.Ca nRead)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > // Reads NetworkStream into a byte buffer.
> > > > > >
> > > > > > byte[] bytes = new byte[tcpClient.Recei veBufferSize];
> > > > > >
> > > > > > // Read can return anything from 0 to numBytesToRead.
> > > > > >
> > > > > > // This method blocks until at least one byte is read.
> > > > > >
> > > > > > netStream.Read (bytes, 0,

(int)tcpClient. ReceiveBufferSi ze);
> > > > > >
> > > > > > // Returns the data received from the host to the console. > > > > > >
> > > > > > string returndata = Encoding.UTF8.G etString (bytes);
> > > > > >
> > > > > > Console.WriteLi ne ("This is what the host returned to

you: "
+
> > > > > >
> > > > > > returndata);
> > > > > >
> > > > > > swr.WriteLine(r eturndata);
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > > else
> > > > > >
> > > > > > {
> > > > > >
> > > > > > Console.WriteLi ne ("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.WriteLi ne(ex.Message);
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > > public void Stop()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > tcpListener.Sto p();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > public void Resume()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > listenerThread. Resume();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > public void Suspend()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > listenerThread. Suspend();
> > > > > >
> > > > > > }
> > > > > >
> > > > > > Regards,
> > > > > >
> > > > > > TulasiKumar
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> >
>
>





Jan 5 '06 #9
Hi,

"TulasiKuma r" <tu*********@na nnacomputers.co m> wrote in message
news:eZ******** ******@TK2MSFTN GP11.phx.gbl...
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.Usi ng
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.


Find below a piece of code that does what you want, it's multi thread , so
you can handle more than one incoming connection

Queue connectionQueue = null;
protected override void OnStart(string[] args)
{
listenerThread = new Thread( new ThreadStart( ListenerMethod) );
listenerThread. Start();
}
protected void ListenerMethod( )
{

Thread workingthread;
Queue unsyncq = new Queue();
connectionQueue = Queue.Synchroni zed( unsyncq);
TcpClient socket;
TcpListener listener = new TcpListener( Config.Port);
listener.Start( );
while( true)
{
socket = listener.Accept TcpClient();
connectionQueue .Enqueue( socket);
workingthread = new Thread( new ThreadStart( TheConnectionHa ndler));
workingthread.S tart();
}
}
public void TheConnectionHa ndler()
{
TcpClient socket= (TcpClient)conn ectionQueue.Deq ueue();
NetAccess netaccess = null;

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
996
by: Newsgroups MICROSOFT | last post by:
Hi, I've search a lot over the Internet and I've found many similar problems. The CurrentChanged event of the BindingManagerBase class DOESNT get fired when the application is working with Framework v:1.1. The problem disappears when the app switches to Framework v:1.0. Is there any solution, or is this a BUG from Microsoft ?
2
4084
by: jajalc | last post by:
Hi all, WE have a windows service using .net and which uses a System.Timers.Timer..all the of code works fine..... but after a extended period of time the timer just stops firing the elasped event. the elasped event is fired every 2 sec and the code which is in the elasped event is multithreaded. This only happens if the service runs for a extended peroid of time..
2
1512
by: Neo The One | last post by:
This is about ASP.NET 1.0, but it may still applies to 1.1 and 2.0. We have a very large web application, some part of the code calls EXE files to do jobs. It all worked fine on Windows 2000 Server until we migrated the app to a completely new Windows Server 2003. In a long running Terminial session, we occasionally (often) see a popup that says 'JIT Debugger was initiated by the user account NT AUTHORITY\NETWORK SERVICE'.
5
1332
by: Yoavo | last post by:
Hi, I wrote a windows service using c#. Is there a way to start the service automatically after it has been installed ? Yoav.
2
3375
by: =?Utf-8?B?TWljaGVsIFNjaGF3YW5u?= | last post by:
Hi all, I try to create a service witch handle the session switch events: Lock, unlocked etc... I can do this with a standard executable like this (it's just an example): //**************************************** //**************************************** public class Event { static WaitHandle listhandle = new WaitHandle { new
1
5141
by: trinityofsouls | last post by:
I am trying to run a windows application from a service. Both the Windows Form App and the Windows Service were created using the .NET 2005 "New Project" Templates. There service is working as intended (It picks up files to be proccessed out of watch directories) however there seems to be an issue when the Windows App is called. I use the below to call the application: ProcessStartInfo theProcess; theProcess = new...
0
2891
by: das | last post by:
Hello all, I am using the SqlDependency to subscribe to any new inserts into a database table, I enabled the DB to be borker ready and subscrbed to Query notifications on the database. My C# Windows service has a simple query that checks if a new entry is made into a table, select * from Cast_Member where isMajor = '1' When I insert a new record into this table with isMajor = 1, then the
1
1647
by: Stuart Parker | last post by:
Hi... I'm messing about with windows services in vb.net 2005 and have the following question. I have a service which has a timer in it, which fires every minute - Textbook stuff I have a windows forms app which I would like to respond to the service firing an event For example. Service's timer triggers, and windows forms app then displays a message saying "Event Fired"
41
11663
by: pbd22 | last post by:
Hi. I know my windows service works when i run it in debug mode on my dev machine. It also works in release mode on my dev machine. But, when I move the service to a production server, it exits immediately with a start/stop/nothing to do error. What could be wrong?
0
905
by: Geoffrey | last post by:
Hello, I'm developping a WCF service. All is good : I have a WPF app. On a button, I call a function to register 2 WCF service (one in tcp, the other in http) But, now, I want to use a windows service in place of a windows app. So, in the onStart, I place the same call than on the button.
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.