Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Difference between Socket and Port

Difference between Socket and Port

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zahid_ash
    wrote on last edited by
    #1

    Hi, What is the difference between Socket and Port. If I use CSocket sock. sock.Create(200); // for server side willit create port and for Cleint side CSocket sock sock.Create(); // will it create socket thanks Regards.

    B 1 Reply Last reply
    0
    • Z zahid_ash

      Hi, What is the difference between Socket and Port. If I use CSocket sock. sock.Create(200); // for server side willit create port and for Cleint side CSocket sock sock.Create(); // will it create socket thanks Regards.

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      From MSDN: "Definition of a Socket A socket is a communication endpoint — an object through which a Windows Sockets application sends or receives packets of data across a network. A socket has a type and is associated with a running process, and it may have a name. Currently, sockets generally exchange data only with other sockets in the same “communication domain,” which uses the Internet Protocol Suite. " "Port A port identifies a unique process for which a service can be provided. In the present context, a port is associated with an application that supports Windows Sockets. The idea is to identify each Windows Sockets application uniquely so you can have more than one Windows Sockets application running on a machine at the same time. " End of MSDN quotes. Normally you don't choose the port to use unless you are a server, and that is only the listener port that is defined. You do however, have a choice to let the server listen on a particualr network if your box is multi-homed (multiple NICs or network cards). This is called "Binding". If your providing a common well known service, it is customary to listen on the port conventionally used for that service. Lets say port 25 for SMTP. When your "accept" returns, the socket connection will actually use a different port for it's communication with the client (usually the next available port) from that point forward leaving the common port to listen for further connection attempts via additional calls to one of the forms of "accept" available. The client usually does not pick the port it will use on it's end. It usually states which family, port, and address it wants to connect to. This means it is saying it wants to connect to port 25 on the server at address whatever. The local port used is arbitrary and is usually just the next available port and in no way required to be any specific port.

      Z 1 Reply Last reply
      0
      • B bob16972

        From MSDN: "Definition of a Socket A socket is a communication endpoint — an object through which a Windows Sockets application sends or receives packets of data across a network. A socket has a type and is associated with a running process, and it may have a name. Currently, sockets generally exchange data only with other sockets in the same “communication domain,” which uses the Internet Protocol Suite. " "Port A port identifies a unique process for which a service can be provided. In the present context, a port is associated with an application that supports Windows Sockets. The idea is to identify each Windows Sockets application uniquely so you can have more than one Windows Sockets application running on a machine at the same time. " End of MSDN quotes. Normally you don't choose the port to use unless you are a server, and that is only the listener port that is defined. You do however, have a choice to let the server listen on a particualr network if your box is multi-homed (multiple NICs or network cards). This is called "Binding". If your providing a common well known service, it is customary to listen on the port conventionally used for that service. Lets say port 25 for SMTP. When your "accept" returns, the socket connection will actually use a different port for it's communication with the client (usually the next available port) from that point forward leaving the common port to listen for further connection attempts via additional calls to one of the forms of "accept" available. The client usually does not pick the port it will use on it's end. It usually states which family, port, and address it wants to connect to. This means it is saying it wants to connect to port 25 on the server at address whatever. The local port used is arbitrary and is usually just the next available port and in no way required to be any specific port.

        Z Offline
        Z Offline
        zahid_ash
        wrote on last edited by
        #3

        From the above answer: "......The client usually does not pick the port it will use on it's end. It usually states which family, port, and address it wants to connect to. This means it is saying it wants to connect to port 25 on the server at address whatever. The local port used is arbitrary and is usually just the next available port and in no way required to be any specific port." ---------------------------- As I undersand the Client get the local next available port , but if the Firewall is intalled on Client end, then Firewall can block the ports to be open by any application. then would it fail to open the any next avaible port on cleint side Regards.

        B J 2 Replies Last reply
        0
        • Z zahid_ash

          From the above answer: "......The client usually does not pick the port it will use on it's end. It usually states which family, port, and address it wants to connect to. This means it is saying it wants to connect to port 25 on the server at address whatever. The local port used is arbitrary and is usually just the next available port and in no way required to be any specific port." ---------------------------- As I undersand the Client get the local next available port , but if the Firewall is intalled on Client end, then Firewall can block the ports to be open by any application. then would it fail to open the any next avaible port on cleint side Regards.

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          I am not sure how firewalls work to be honest. Bits and pieces here and there but nothing substantial enough to claim an understanding. I have not looked into the layers of the OSI model below that needed to implement sockets so I'd be a little reluctant to venture there. I do know that when my socket apps attempt to connect to a server, even through a loopback address (long story) the local firewalls usually catch it and prompt the user. It's almost consistent with your statements so I would guess your on the right track. Sorry I can't be much help.

          1 Reply Last reply
          0
          • Z zahid_ash

            From the above answer: "......The client usually does not pick the port it will use on it's end. It usually states which family, port, and address it wants to connect to. This means it is saying it wants to connect to port 25 on the server at address whatever. The local port used is arbitrary and is usually just the next available port and in no way required to be any specific port." ---------------------------- As I undersand the Client get the local next available port , but if the Firewall is intalled on Client end, then Firewall can block the ports to be open by any application. then would it fail to open the any next avaible port on cleint side Regards.

            J Offline
            J Offline
            Justin Tay
            wrote on last edited by
            #5

            Firewalls are mainly used to block incoming packets rather than outgoing packets. If it is a firewall blocking outgoing packets unless that application is a "trusted" application, then it would have to be manually added by the user anyway. The usefulness of a firewall filtering outgoing connections is debatable, because this means that the malicious software is already installed on the client computer so the battle is more or less already lost. The actual port number for outgoing sockets is usually not important and it's usually some rather high number (as the lower port numbers are all reserved for specific applications, eg 21 for ftp, 80 for http) http://www.iana.org/assignments/port-numbers[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups