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. MFC Sockets - Urgent!!!

MFC Sockets - Urgent!!!

Scheduled Pinned Locked Moved C / C++ / MFC
c++
2 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.
  • V Offline
    V Offline
    Vladimir Georgiev
    wrote on last edited by
    #1

    The following is my code: CAsyncSocket socksrv; char buff[500]; ... UINT ClientThread(LPVOID lParam) { CSocket* s = new CSocket; s = (CSocket*) lParam; while (1) { s->Receive(buff, 500*sizeof(char), 0); if (strlen(buff)) { ::SetFocus(NULL); AfxMessageBox(buff); } } return 0; } UINT ServerThread(LPVOID lParam) { CSocket s; socksrv.Create(55599); socksrv.Listen(); while (1) { if (socksrv.Accept(s)) { AfxBeginThread(ClientThread, (LPVOID) &s); } } return 0; } void CServerDlg::OnStartServer() { AfxBeginThread(ServerThread, NULL); } When I execute the following, and try to connect the client, an exception occurs. Please tell me where my mistake is, and if you know what the multithreading sequence must be using CSocket or CAsyncSocket... Thank you! "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

    S 1 Reply Last reply
    0
    • V Vladimir Georgiev

      The following is my code: CAsyncSocket socksrv; char buff[500]; ... UINT ClientThread(LPVOID lParam) { CSocket* s = new CSocket; s = (CSocket*) lParam; while (1) { s->Receive(buff, 500*sizeof(char), 0); if (strlen(buff)) { ::SetFocus(NULL); AfxMessageBox(buff); } } return 0; } UINT ServerThread(LPVOID lParam) { CSocket s; socksrv.Create(55599); socksrv.Listen(); while (1) { if (socksrv.Accept(s)) { AfxBeginThread(ClientThread, (LPVOID) &s); } } return 0; } void CServerDlg::OnStartServer() { AfxBeginThread(ServerThread, NULL); } When I execute the following, and try to connect the client, an exception occurs. Please tell me where my mistake is, and if you know what the multithreading sequence must be using CSocket or CAsyncSocket... Thank you! "Needless redundancy is the hobgoblin of software engineering." - Peter Darnell

      S Offline
      S Offline
      Shamoon
      wrote on last edited by
      #2

      Vladimir Georgiev wrote: if you know what the multithreading sequence must be using CSocket or CAsyncSocket Never use MFC socket classes in Multithreaded environment, otherwise you'll be between the devil and the deep sea. MFC not allows you to pass CSocket/CAsync objects directly from one thread to another. You have to use references for that purpose. Have a look here[^]

      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