473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: I am lost, should i use TCPClient or Socket?

Hi!

I am just beginning to learn about the TcpListener and TcpClient and Socket.

I have figured out the TcpListener, it is used for booth in and outgoing
requests, right?

But when to use the TcpClient and when to use the Socket?

Regards
Martin
Aug 14 '06 #1
2 2850
Martin,

I would always use TcpClient/TcpListener. You really don't have a
reason to not use TcpClient, since it exposes the underlying Socket through
the Client property. So if you need to change something on the Socket that
TcpClient is using, you can do so directly.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Martin Arvidsson" <ye*******@ms.c omwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Hi!

I am just beginning to learn about the TcpListener and TcpClient and
Socket.

I have figured out the TcpListener, it is used for booth in and outgoing
requests, right?

But when to use the TcpClient and when to use the Socket?

Regards
Martin

Aug 14 '06 #2
Hi Martin,
I am just beginning to learn about the TcpListener and TcpClient and Socket.

I have figured out the TcpListener, it is used for booth in and outgoing requests, right?
TcpListener is used to establish incoming connections. From a TcpListener you can accept either a Socket or TcpClient (your choice)
that you can use for two-way communication.
But when to use the TcpClient and when to use the Socket?
You can use either a TcpClient or Socket on a client machine to connect to a host that is using a TcpListener. On the client, you
create the TcpClient or Socket. On the server, the TcpListener creates one for each incoming connection. Just accept the
implementation that you want to use.

As Nicholas said, use should probably use a TcpClient, on both the client and server. There really is no reason not to since it
exposes the Socket anyway and it wraps some common implementation details too.

HTH

--
- Dave Sexton
Aug 14 '06 #3

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

Similar topics

4
4335
by: Christopher H. Laco | last post by:
I'm having a problem with the TcpClient that I can only conclude is either a feature, or a complete misunderstanding of the docs on my part. In a nutshell, I'm simply performing the following sequence with a server: connect write(50 bytes) read(2002 bytes) write(50 bytes) read(2002 bytes)
3
9089
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on the client machine to close per my network app the computer fills up w/ thousands of these :0 TCP foobox:8888 localhost:2188 TIME_WAIT :0 TCP foobox:8888 localhost:2189 TIME_WAIT :0 TCP foobox:8888 localhost:2190 TIME_WAIT
1
3024
by: alex002 | last post by:
Dear all, I am writing to a C# program to connect to the telnet server and getting data; however, I know that I can use either TCPClient and Asyncronous Socket to do the program. However, I don't know which is better and why. Can any one tell me about this? Thank you for all of your help. Alex
5
72242
by: Horst Walter | last post by:
What is wrong here? IPAddress ipAddress = IPAddress.Parse("10.10.20.1"); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, this.port); this.tcpClient = new TcpClient(ipEndPoint); // PROBLEM HERE => Exception: "The requested address is not valid in its context" This works:
3
28641
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work slowly, about 4 seconds between send and receive. In our production environment with hundreds of transactions it was truly costly. a while ago i changed de TcpClient object. Now i am using a Socket (System.Net.Sockets.Socket) object and it...
4
6313
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
1
4530
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client closes the connection so I can exit my listener code. Here is what I have tried. First I asked MSDN and they said..
4
20456
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am wondering if I am using TCPClient class in C#, how to setup timeout value? Timeout I mean, when connects to server for the 1st time, and during <timeoutinterval, if no server response is received, the GetStream method will return will return other than wait forever. thanks in advance,
5
7291
by: puzzlecracker | last post by:
It looks like i need to get IPEndPoint first, but I cannot figure out from msdn the eventual obtainment of machine name and port number. Please suggest a solution. Thanks
0
8305
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
8825
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
7324
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...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
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
2726
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
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
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.