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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to scan for a port in the lan.

How to scan for a port in the lan.

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminc++tutorialquestionlounge
6 Posts 2 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.
  • R Offline
    R Offline
    rk r
    wrote on last edited by
    #1

    This might be a very trivial question for most of you. I want to know how to write a program in vc++ for scanning a particular port on the lan. I have written a chat program, I want that whenever a user starts the client, it scans the network and finds the ip for connecting, if no server is found it will become a server. Most messengers do the same thing I suppose. Thanks in advance. I dream so I do.

    G 1 Reply Last reply
    0
    • R rk r

      This might be a very trivial question for most of you. I want to know how to write a program in vc++ for scanning a particular port on the lan. I have written a chat program, I want that whenever a user starts the client, it scans the network and finds the ip for connecting, if no server is found it will become a server. Most messengers do the same thing I suppose. Thanks in advance. I dream so I do.

      G Offline
      G Offline
      Ghasrfakhri
      wrote on last edited by
      #2

      Hi I have a suggest,I think it is better to use othere way to find server. If you wana to use your messanger on a LAN you can use broadcast messages. when a client want to find server Send a BC message on the network if server peresent answer it by sending message contain its IP & other information and if isn't present the client can work as a server after some try and listen for clients BC message. Iman Ghasrfakhri

      R 1 Reply Last reply
      0
      • G Ghasrfakhri

        Hi I have a suggest,I think it is better to use othere way to find server. If you wana to use your messanger on a LAN you can use broadcast messages. when a client want to find server Send a BC message on the network if server peresent answer it by sending message contain its IP & other information and if isn't present the client can work as a server after some try and listen for clients BC message. Iman Ghasrfakhri

        R Offline
        R Offline
        rk r
        wrote on last edited by
        #3

        Yes, that's exactly what I want to do, but I donot know how to implement. Could you please help me with code. Thanks. I dream so I do.

        G 1 Reply Last reply
        0
        • R rk r

          Yes, that's exactly what I want to do, but I donot know how to implement. Could you please help me with code. Thanks. I dream so I do.

          G Offline
          G Offline
          Ghasrfakhri
          wrote on last edited by
          #4

          Hi in this code I listen a socket to receive server's response and then Send BC message to the network (this is a client action) // m_LSocket is a Class member & its type is CAsyncSocket * m_LSocket->Create(1000); m_LSocket->Listen(); CAsyncSocket s; s.Create(334400,SOCK_DGRAM); BOOL bOptVal = TRUE; s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL)); char buf[256]; CString Address("255.255.255.255"); // broadcast IP unsigned int port = 1000; // Port No. strcpy(buf,"Requesting Connection"); // Message s.SendTo(buf,256,port); // Sending On the server side you most listen a Datagram socke (SOCK_DGRAM), and wait to receive a connection request. Is it enough.;) Iman Ghasrfakhri

          R 2 Replies Last reply
          0
          • G Ghasrfakhri

            Hi in this code I listen a socket to receive server's response and then Send BC message to the network (this is a client action) // m_LSocket is a Class member & its type is CAsyncSocket * m_LSocket->Create(1000); m_LSocket->Listen(); CAsyncSocket s; s.Create(334400,SOCK_DGRAM); BOOL bOptVal = TRUE; s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL)); char buf[256]; CString Address("255.255.255.255"); // broadcast IP unsigned int port = 1000; // Port No. strcpy(buf,"Requesting Connection"); // Message s.SendTo(buf,256,port); // Sending On the server side you most listen a Datagram socke (SOCK_DGRAM), and wait to receive a connection request. Is it enough.;) Iman Ghasrfakhri

            R Offline
            R Offline
            rk r
            wrote on last edited by
            #5

            Thank you very much for the help. ;) May I ask you one more favour, could you please give me the server code aswell. Thanks again.:cool: I dream so I do.

            1 Reply Last reply
            0
            • G Ghasrfakhri

              Hi in this code I listen a socket to receive server's response and then Send BC message to the network (this is a client action) // m_LSocket is a Class member & its type is CAsyncSocket * m_LSocket->Create(1000); m_LSocket->Listen(); CAsyncSocket s; s.Create(334400,SOCK_DGRAM); BOOL bOptVal = TRUE; s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL)); char buf[256]; CString Address("255.255.255.255"); // broadcast IP unsigned int port = 1000; // Port No. strcpy(buf,"Requesting Connection"); // Message s.SendTo(buf,256,port); // Sending On the server side you most listen a Datagram socke (SOCK_DGRAM), and wait to receive a connection request. Is it enough.;) Iman Ghasrfakhri

              R Offline
              R Offline
              rk r
              wrote on last edited by
              #6

              Ok can anybody tell me some good books from where i can learn about udp broadcasting or any web tutorial. I dream so I do.

              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