What are Sockets? And how to develop in C#?

Asked

Viewed 296 times

9

I have to develop a socket, but I don’t know what it is or how it works! I wanted to know what it takes to create a C#Socket, I am using Visual Studio as IDE.

1 answer

13


Socket (socket) is the final point of data communication from one process to another on the same machine or on another. It is a mechanism normally provided by operating systems to establish data communication.

This can be achieved with the class Socket no . NET (for example on the documentation page).

Basic example:

using System.Net.Sockets;
...
var Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

I put in the Github for future reference.

There are some forms of communication, types of "sockets" different (Stream, Dgram, Raw, Rdm, Seqpacket) and protocols available (TCP, UDP, ICMP, Ipv4, Ipv6, among others).

You should only use it to build low-level communication mechanisms. You have to have a good understanding of data communication. In general who uses this, is who will make custom FTP mechanism, HTTP, SMTP, etc., or who needs the use of direct communication at the lowest level and is willing to deal with all necessary details. If you don’t have a good reason to use it, prefer another mechanism.

Practical examples.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.