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
R

role1

@role1
About
Posts
2
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Multi threading in c++
    R role1

    hi i am using the below code for dummy multithreading application. first function listens request and the thread started with thread function but some client start receving data but some one not get the single respomnse back . can any one help me what's gona wong with this code thanks ///////the server function////////////////// void thread::startserver() { DWORD dwStatus; WSAEVENT handles[1]; struct sockaddr_in cli_addr; int clilen = sizeof(cli_addr); memset(&cli_addr,0,sizeof(struct sockaddr)); printf("***********server started****************\n"); while (TRUE) { handles[0] = WSACreateEvent(); WSAEventSelect(m_hSockethndl, handles[0], FD_ACCEPT); dwStatus = WSAWaitForMultipleEvents(1, handles, TRUE, 50, FALSE); if (dwStatus == WSA_WAIT_EVENT_0) { SOCKET cli_socket; cli_socket=-1; cli_socket = accept(m_hSockethndl, (struct sockaddr *) &cli_addr, &clilen); // set linger option LINGER linger; linger.l_onoff = 1; linger.l_linger = 0; setsockopt(cli_socket, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(LINGER)); //setsockopt(cli_socket, IPPROTO_TCP, TCP_NODELAY, NULL, 0); int flag = 1; int result = setsockopt(cli_socket, /* socket affected */ IPPROTO_TCP, /* set option at TCP level */ TCP_NODELAY, /* name of option */ (char *) &flag, /* the cast is historical cruft */ sizeof(int)); /* length of option value */ if (result < 0) { printf("Client Socket No Delay Option Failed"); } //printf("Thread started with the server socket=%d and client port=%d and ip=%s\n",cli_socket,cli_addr.sin_port,inet_ntoa(cli_addr.s in_addr)); /*threadParmas thparam; memset(&thparam,0,sizeof(threadParmas)); thparam.cli_addrth=cli_addr; thparam.threadsocket=cli_socket;*/ //CreateThread(NULL, 0, StartThread, &thparam, 0, &dwThreadID); CreateThread(NULL, 0, StartThread, &cli_socket, 0, &dwThreadID); FD_SET(cli_socket, &set_sockets); } WSACloseEvent(handles[0]); } } //////////////////the thread function//////////////////// DWORD WINAPI thread::StartThread (void * thparam) { /* struct threadParmas threadparam; threadparam.threadsocket=((struct threadParmas *)thparam)->threadsocket; threadparam.cli_addrth=((struct threadParmas *)thparam)->cli_addrth;*/ SOCKET socket_handle; u_short Clientport; //socket_handle=threadparam.threadsocket; socket_handle=*(SOCKET *)thparam; //Clientport=ntohs(threadparam.cli_addrth.sin_port); char data[256]; char Resdata[512]; memset(data,0,256); memset(Resdata,0,512); int counter=1; int bytes =1;

    C / C++ / MFC c++ sysadmin help

  • Multi threading in c++ [modified]
    R role1

    hi i am using the below code for dummy multithreading application. first function listens request and the thread started with thread function but some client start receving data but some one not get the single respomnse back . can any one help me what's gona wong with this code thanks ///////the server function////////////////// void thread::startserver() { DWORD dwStatus; WSAEVENT handles[1]; struct sockaddr_in cli_addr; int clilen = sizeof(cli_addr); memset(&cli_addr,0,sizeof(struct sockaddr)); printf("***********server started****************\n"); while (TRUE) { handles[0] = WSACreateEvent(); WSAEventSelect(m_hSockethndl, handles[0], FD_ACCEPT); dwStatus = WSAWaitForMultipleEvents(1, handles, TRUE, 50, FALSE); if (dwStatus == WSA_WAIT_EVENT_0) { SOCKET cli_socket; cli_socket=-1; cli_socket = accept(m_hSockethndl, (struct sockaddr *) &cli_addr, &clilen); // set linger option LINGER linger; linger.l_onoff = 1; linger.l_linger = 0; setsockopt(cli_socket, SOL_SOCKET, SO_LINGER, (char *)&linger, sizeof(LINGER)); //setsockopt(cli_socket, IPPROTO_TCP, TCP_NODELAY, NULL, 0); int flag = 1; int result = setsockopt(cli_socket, /* socket affected */ IPPROTO_TCP, /* set option at TCP level */ TCP_NODELAY, /* name of option */ (char *) &flag, /* the cast is historical cruft */ sizeof(int)); /* length of option value */ if (result < 0) { printf("Client Socket No Delay Option Failed"); } //printf("Thread started with the server socket=%d and client port=%d and ip=%s\n",cli_socket,cli_addr.sin_port,inet_ntoa(cli_addr.s in_addr)); /*threadParmas thparam; memset(&thparam,0,sizeof(threadParmas)); thparam.cli_addrth=cli_addr; thparam.threadsocket=cli_socket;*/ //CreateThread(NULL, 0, StartThread, &thparam, 0, &dwThreadID); CreateThread(NULL, 0, StartThread, &cli_socket, 0, &dwThreadID); FD_SET(cli_socket, &set_sockets); } WSACloseEvent(handles[0]); } } //////////////////the thread function//////////////////// DWORD WINAPI thread::StartThread (void * thparam) { /* struct threadParmas threadparam; threadparam.threadsocket=((struct threadParmas *)thparam)->threadsocket; threadparam.cli_addrth=((struct threadParmas *)thparam)->cli_addrth;*/ SOCKET socket_handle; u_short Clientport; //socket_handle=threadparam.threadsocket; socket_handle=*(SOCKET *)thparam; //Clientport=ntohs(threadparam.cli_addrth.sin_port); char data[256]; char Resdata[512]; memset(data,0,256); memset(Resdata,0,512); int counter=1; int bytes =1;

    COM c++ sysadmin help
  • Login

  • Don't have an account? Register

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