471,306 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

How can i detect TCP/Ip pcaketsin cSharp

Hi all,
I am new in Netwrok porgraming in cSharp.how can i detect Tcp/Ip packet in
c#.Net.Any body knows please tell me, what are the interfaces or classes
are
supported regrading on TCP/IP packets.Please tell me any website refrences
or any Source code examples.This is very urgent requirement.

Thanks in advance,
Regards,
Tulasi Kumar.


Dec 26 '05 #1
5 2097
It depends on what level you want to work.

In .NET the functionality you need is in System.Net and System.NET.Sockets
namespaces.

Socket class supports different types of socket ( stream, dgram, raw )

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

"TulasiKumar" <tu*********@nannacomputers.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
Hi all,
I am new in Netwrok porgraming in cSharp.how can i detect Tcp/Ip packet
in
c#.Net.Any body knows please tell me, what are the interfaces or classes
are
supported regrading on TCP/IP packets.Please tell me any website
refrences
or any Source code examples.This is very urgent requirement.

Thanks in advance,
Regards,
Tulasi Kumar.



Dec 26 '05 #2
Thank u for giving the reply.
When ever any data is coming to the TCP/IP port i will take the data and
do some operations on that packet.Before doing the operations I have to take
the Packet data.How can i get the packet data from TCP port? can u give me
ur help regarding on this.

thanks in advance.
Regards,
Tulaskumar

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
It depends on what level you want to work.

In .NET the functionality you need is in System.Net and System.NET.Sockets namespaces.

Socket class supports different types of socket ( stream, dgram, raw )

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

"TulasiKumar" <tu*********@nannacomputers.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
Hi all,
I am new in Netwrok porgraming in cSharp.how can i detect Tcp/Ip packet in
c#.Net.Any body knows please tell me, what are the interfaces or classes are
supported regrading on TCP/IP packets.Please tell me any website
refrences
or any Source code examples.This is very urgent requirement.

Thanks in advance,
Regards,
Tulasi Kumar.






Dec 26 '05 #3
Check the docs for the TcpClient and TcpListener

TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("www.contoso.com", 11002);
NetworkStream netStream = tcpClient.GetStream ();

if (netStream.CanWrite)
{
Byte[] sendBytes = Encoding.UTF8.GetBytes ("Is anybody there?");
netStream.Write (sendBytes, 0, sendBytes.Length);
}
else
{
Console.WriteLine ("You cannot write data to this stream.");
tcpClient.Close ();

// Closing the tcpClient instance does not close the network stream.
netStream.Close ();
return;
}

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);

}
else
{
Console.WriteLine ("You cannot read data from this stream.");
tcpClient.Close ();

// Closing the tcpClient instance does not close the network stream.
netStream.Close ();
return;
}
netStream.Close();
--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"TulasiKumar" <tu*********@nannacomputers.com> wrote in message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
Thank u for giving the reply.
When ever any data is coming to the TCP/IP port i will take the data and
do some operations on that packet.Before doing the operations I have to
take
the Packet data.How can i get the packet data from TCP port? can u give me
ur help regarding on this.

thanks in advance.
Regards,
Tulaskumar

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> It depends on what level you want to work.
>
> In .NET the functionality you need is in System.Net and

System.NET.Sockets
> namespaces.
>
> Socket class supports different types of socket ( stream, dgram, raw )
>
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKumar" <tu*********@nannacomputers.com> wrote in message
> news:Ov**************@TK2MSFTNGP15.phx.gbl...
> > Hi all,
> > I am new in Netwrok porgraming in cSharp.how can i detect Tcp/Ip packet > > in
> > c#.Net.Any body knows please tell me, what are the interfaces or classes > > are
> > supported regrading on TCP/IP packets.Please tell me any website
> > refrences
> > or any Source code examples.This is very urgent requirement.
> >
> > Thanks in advance,
> > Regards,
> > Tulasi Kumar.
> >
> >
> >
> >
> >
> >
> >
> >

>
>


Dec 26 '05 #4
My heartful thanks to Vadym Stetsyak giving ur immediate reply.I will try
it.In this way,I have struck up from few days.Where i have to go u r giving
the way.I will try it and i will give the result regarding on this.Once
again very very thanks Vadym Stetsyak
Regrads
tulasi kumar
"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:ug*************@TK2MSFTNGP15.phx.gbl...
Check the docs for the TcpClient and TcpListener

TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("www.contoso.com", 11002);
NetworkStream netStream = tcpClient.GetStream ();

if (netStream.CanWrite)
{
Byte[] sendBytes = Encoding.UTF8.GetBytes ("Is anybody there?");
netStream.Write (sendBytes, 0, sendBytes.Length);
}
else
{
Console.WriteLine ("You cannot write data to this stream.");
tcpClient.Close ();

// Closing the tcpClient instance does not close the network stream.
netStream.Close ();
return;
}

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);

}
else
{
Console.WriteLine ("You cannot read data from this stream.");
tcpClient.Close ();

// Closing the tcpClient instance does not close the network stream.
netStream.Close ();
return;
}
netStream.Close();
--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"TulasiKumar" <tu*********@nannacomputers.com> wrote in message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
Thank u for giving the reply.
When ever any data is coming to the TCP/IP port i will take the data and do some operations on that packet.Before doing the operations I have to take
the Packet data.How can i get the packet data from TCP port? can u give me ur help regarding on this.

thanks in advance.
Regards,
Tulaskumar

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> It depends on what level you want to work.
>
> In .NET the functionality you need is in System.Net and

System.NET.Sockets
> namespaces.
>
> Socket class supports different types of socket ( stream, dgram, raw ) >
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKumar" <tu*********@nannacomputers.com> wrote in message
> news:Ov**************@TK2MSFTNGP15.phx.gbl...
> > Hi all,
> > I am new in Netwrok porgraming in cSharp.how can i detect Tcp/Ip

packet
> > in
> > c#.Net.Any body knows please tell me, what are the interfaces or

classes
> > are
> > supported regrading on TCP/IP packets.Please tell me any website
> > refrences
> > or any Source code examples.This is very urgent requirement.
> >
> > Thanks in advance,
> > Regards,
> > Tulasi Kumar.
> >
> >
> >
> >
> >
> >
> >
> >
>
>





Dec 26 '05 #5
hi Vadym Stetsyak,
i have prepared one windows service in c#.net .This is service about TcpIp
packets data checking.I had wrriten the code as per your advice.so,my
problem is how can i insatll this windows service.please tell me ur advice
,i greatly revice ur advice.

thanks in advance
regards
tulasi

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:ug*************@TK2MSFTNGP15.phx.gbl...
Check the docs for the TcpClient and TcpListener

TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("www.contoso.com", 11002);
NetworkStream netStream = tcpClient.GetStream ();

if (netStream.CanWrite)
{
Byte[] sendBytes = Encoding.UTF8.GetBytes ("Is anybody there?");
netStream.Write (sendBytes, 0, sendBytes.Length);
}
else
{
Console.WriteLine ("You cannot write data to this stream.");
tcpClient.Close ();

// Closing the tcpClient instance does not close the network stream.
netStream.Close ();
return;
}

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);

}
else
{
Console.WriteLine ("You cannot read data from this stream.");
tcpClient.Close ();

// Closing the tcpClient instance does not close the network stream.
netStream.Close ();
return;
}
netStream.Close();
--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"TulasiKumar" <tu*********@nannacomputers.com> wrote in message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
Thank u for giving the reply.
When ever any data is coming to the TCP/IP port i will take the data and do some operations on that packet.Before doing the operations I have to take
the Packet data.How can i get the packet data from TCP port? can u give me ur help regarding on this.

thanks in advance.
Regards,
Tulaskumar

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> It depends on what level you want to work.
>
> In .NET the functionality you need is in System.Net and

System.NET.Sockets
> namespaces.
>
> Socket class supports different types of socket ( stream, dgram, raw ) >
> --
> Vadym Stetsyak aka Vadmyst
> http://vadmyst.blogspot.com
>
> "TulasiKumar" <tu*********@nannacomputers.com> wrote in message
> news:Ov**************@TK2MSFTNGP15.phx.gbl...
> > Hi all,
> > I am new in Netwrok porgraming in cSharp.how can i detect Tcp/Ip

packet
> > in
> > c#.Net.Any body knows please tell me, what are the interfaces or

classes
> > are
> > supported regrading on TCP/IP packets.Please tell me any website
> > refrences
> > or any Source code examples.This is very urgent requirement.
> >
> > Thanks in advance,
> > Regards,
> > Tulasi Kumar.
> >
> >
> >
> >
> >
> >
> >
> >
>
>





Dec 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Gouri | last post: by
4 posts views Thread by Frank Meng | last post: by
2 posts views Thread by Roger Maynard | last post: by
3 posts views Thread by akowald | last post: by
3 posts views Thread by dw | last post: by
3 posts views Thread by =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post: by
reply views Thread by rosydwin | last post: by

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.