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. Winsock question

Winsock question

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelploungelearning
4 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.
  • S Offline
    S Offline
    Scozturk
    wrote on last edited by
    #1

    Hi! I am trying to create a chat application using the async socket mode ( I dont need more than 20 connections at a time so I didnt use overlapped mode). My chat program has a server and clients connected to it. The server returns to all clients the messages sent by a client and all the clients view the same message. The problem is that my chat server can resend a message which came from a client to only one client... I think I made a mistake in the FD_ACCEPT message: case FD_ACCEPT: { sockaddr_in remoteAddr; int iRemoteAddrLen; iRemoteAddrLen = sizeof(remoteAddr); hRemoteSocket = accept(hSocket, (sockaddr*)&remoteAddr, &iRemoteAddrLen); } break; This code accepts all incoming clients but only lets me communicate with just one :wtf:! How can I communicate with more clients :confused:?(Do I have to create a new socket for all new clients? :omg: ) Thank you very much for your future answers! :sigh: Well... I am a beginner ...

    J P 2 Replies Last reply
    0
    • S Scozturk

      Hi! I am trying to create a chat application using the async socket mode ( I dont need more than 20 connections at a time so I didnt use overlapped mode). My chat program has a server and clients connected to it. The server returns to all clients the messages sent by a client and all the clients view the same message. The problem is that my chat server can resend a message which came from a client to only one client... I think I made a mistake in the FD_ACCEPT message: case FD_ACCEPT: { sockaddr_in remoteAddr; int iRemoteAddrLen; iRemoteAddrLen = sizeof(remoteAddr); hRemoteSocket = accept(hSocket, (sockaddr*)&remoteAddr, &iRemoteAddrLen); } break; This code accepts all incoming clients but only lets me communicate with just one :wtf:! How can I communicate with more clients :confused:?(Do I have to create a new socket for all new clients? :omg: ) Thank you very much for your future answers! :sigh: Well... I am a beginner ...

      J Offline
      J Offline
      Jagadeesh VN
      wrote on last edited by
      #2

      You may have to keep a reference to all the client sockets that is connected to your server sockets. You can use an array / list of socket descriptors for this. "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

      1 Reply Last reply
      0
      • S Scozturk

        Hi! I am trying to create a chat application using the async socket mode ( I dont need more than 20 connections at a time so I didnt use overlapped mode). My chat program has a server and clients connected to it. The server returns to all clients the messages sent by a client and all the clients view the same message. The problem is that my chat server can resend a message which came from a client to only one client... I think I made a mistake in the FD_ACCEPT message: case FD_ACCEPT: { sockaddr_in remoteAddr; int iRemoteAddrLen; iRemoteAddrLen = sizeof(remoteAddr); hRemoteSocket = accept(hSocket, (sockaddr*)&remoteAddr, &iRemoteAddrLen); } break; This code accepts all incoming clients but only lets me communicate with just one :wtf:! How can I communicate with more clients :confused:?(Do I have to create a new socket for all new clients? :omg: ) Thank you very much for your future answers! :sigh: Well... I am a beginner ...

        P Offline
        P Offline
        Phil Speller
        wrote on last edited by
        #3

        Scolinks wrote: How can I communicate with more clients ?(Do I have to create a new socket for all new clients? ) Indeed you do. The socket you initially create on your server is just used to accept new connections from clients. When you call accept it will return a socket which you use to communicate with that client. You'll need to keep track of all sockets created by th accept fn. Phil

        S 1 Reply Last reply
        0
        • P Phil Speller

          Scolinks wrote: How can I communicate with more clients ?(Do I have to create a new socket for all new clients? ) Indeed you do. The socket you initially create on your server is just used to accept new connections from clients. When you call accept it will return a socket which you use to communicate with that client. You'll need to keep track of all sockets created by th accept fn. Phil

          S Offline
          S Offline
          Scozturk
          wrote on last edited by
          #4

          OK! Thanks a lot! I'll try to figure out how I can create a socket array! Well... I am a beginner ...

          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