Creating a TCP/IP Connection

B

BillB

Hi,

I'm new to C# and was wondering how I can create a TCP/IP connection.

I would like to be able to create a connection to a web server on a specific
port fire of some commands to it and then once I'm finished close the
connection again.
I'm looking for something similar to how HyperTerminal connects to an IP
address and allows you to type commands to it.

Any info is appreciated.
 
N

Nicholas Paldino [.NET/C# MVP]

Bill,

Have you looked at the Socket class in the System.Net namespace? It
will allow you to create the connection you are looking for.

However, I wouldn't recommend that. If you are connecting to a web
server, you want a higher level abstraction to issue commands and read the
responses from the server. In this case, I would recommend using the
HttpWebRequest and HttpWebResponse classes, or the WebClient class, also in
the System.Net namespace.
 
J

Jeroen Mostert

BillB said:
I'm looking for something similar to how HyperTerminal connects to an IP
address and allows you to type commands to it.
That's called Telnet.
 
J

John Rivers

Hi,

I'm new to C# and was wondering how I can create a TCP/IP connection.

I would like to be able to create a connection to a web server on a specific
port fire of some commands to it and then once I'm finished close the
connection again.
I'm looking for something similar to how HyperTerminal connects to an IP
address and allows you to type commands to it.

Any info is appreciated.

System.Net.TcpClient

it is mostly a convenience class on top of Socket

I would spend a bit of extra time and use Sockets directly

TcpClient is horribly "encapsulated" and you usually end up needing a
feature that you can get easily if you use Socket directly
 
B

BillB

Hey
I was thinking of going down the Sockets route, was just looking for some
info about it.
My little test app is going to have connect and disconnect buttons, and a
few other buttons that will have some preloaded request to send to the
server, as far as i know i won't recieve anything back from the server
(going by what i get hen using HyperTerminal) the actual server is used to
control an intercom system so i am sending it connection requests and a few
other commands.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top