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 send and receive data use the same port?

How to send and receive data use the same port?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 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.
  • A Offline
    A Offline
    alan top
    wrote on last edited by
    #1

    How to send and receive data use the same port? alantop

    D 2 Replies Last reply
    0
    • A alan top

      How to send and receive data use the same port? alantop

      D Offline
      D Offline
      darkcloud 42o
      wrote on last edited by
      #2

      what type of xfer and client or server??

      D 1 Reply Last reply
      0
      • D darkcloud 42o

        what type of xfer and client or server??

        D Offline
        D Offline
        darkcloud 42o
        wrote on last edited by
        #3

        and are you talking about send files or just communcating...?

        1 Reply Last reply
        0
        • A alan top

          How to send and receive data use the same port? alantop

          D Offline
          D Offline
          darkcloud 42o
          wrote on last edited by
          #4

          //basic send and recieve is... #include #include #pragma comment(lib,"ws2_32") WSAData wsaData; WORD wVersionRequested; wVersionRequested=MAKEWORD(2, 2); WSAStartup( wVersionRequested, &wsaData ); std::string rawcmd; SOCKET communcationsock; SOCKET ListenSocket; SOCKADDR_IN service; ListenSocket = socket(AF_INET, SOCK_STREAM, 0); service.sin_family = AF_INET; service.sin_addr.s_addr = INADDR_ANY; service.sin_port = htons(21); if (bind( ListenSocket, (SOCKADDR*) &service, sizeof(service)) == SOCKET_ERROR) { printf("bind() failed.\n"); } listen( ListenSocket, 1 ); communcationsock=SOCKET_ERROR; while(communcationsock == SOCKET_ERROR) { communcationsock = accept( ListenSocket, NULL, NULL); } bytesRecv = recv( communcationsock, CMD, 128, 0 ); rawcmd.assign(CMD, bytesRecv); if(rawcmd=="..."){ char onconn[128]="Can You Hear Me\r\n"; send( communcationsock, onconn, strlen(onconn), 0 ); } //Basicallly you have to open up a socket for communication.. then you can open up //another sock separately and send files using the same principal. -- modified at 0:02 Saturday 1st July, 2006

          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