Click here to Skip to main content
15,912,932 members
Home / Discussions / COM
   

COM

 
QuestionActiveX Pin
Anil K P1-Jul-07 22:52
Anil K P1-Jul-07 22:52 
Questionunderstanding COM Pin
KASR11-Jul-07 21:32
KASR11-Jul-07 21:32 
AnswerRe: understanding COM Pin
CPallini1-Jul-07 22:01
mveCPallini1-Jul-07 22:01 
QuestionNot able to create folders on exchange 2003 on Windows 2003 Pin
kaushik_Manoj1-Jul-07 19:11
kaushik_Manoj1-Jul-07 19:11 
QuestionHow to datas import in Grd to Excel sheet Pin
Ranjith Joseph Selvaraj29-Jun-07 23:47
Ranjith Joseph Selvaraj29-Jun-07 23:47 
QuestionSetting computer name with WMI Pin
one-trick-pony29-Jun-07 7:07
one-trick-pony29-Jun-07 7:07 
Questionusing asp.net2.0, in case of Gridview control if we dont use Sqldatasource control ,can we use inbuilt edit update.. functionality? Pin
yogita charhate28-Jun-07 23:29
yogita charhate28-Jun-07 23:29 
QuestionMulti threading in c++ [modified] Pin
role127-Jun-07 20:25
role127-Jun-07 20:25 
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;

while(bytes)
{

WSAEVENT we = WSACreateEvent();
WSAEVENT handles[1];
handles[0] = we;
WSAEventSelect(socket_handle, we, FD_READ | FD_CLOSE);
//receiving data from client
for (int i = 0; i < WAIT_MULTIPLE; i++)
{
DWORD available = WSAWaitForMultipleEvents(1, handles, TRUE, WAIT_TIME, FALSE);
if (available == WSA_WAIT_EVENT_0)
{
if ((bytes = recv(socket_handle, data, 256, 0)) < 0)
{
int er = WSAGetLastError();
printf("Error=%d while receive data from socket %d\n",er,socket_handle);
bytes = 0;
break;
}
else
break;
}
}

WSACloseEvent(we);

strcpy_s(Resdata,512,"Response send Ack");

if(bytes)
{
//printf("socket %d Message %3d received client port=%d, ip=%s size=%d\n",socket_handle,counter,Clientport,inet_ntoa(thread param.cli_addrth.sin_addr),bytes);
//go to sleep for internal processing
//printf("socket %d Message %3d received size %d %s\n",socket_handle,counter,bytes,data);
Sleep(2000);

//sending the dummy response to the client
if (send(socket_handle, Resdata, strlen(Resdata), 0) != strlen(Resdata))
{
int er = WSAGetLastError();
printf("ERROR %d IN SENDING %d RESPONSE by socket =%d\n",er,counter,socket_handle);
return 0;
}
//printf("***Response %3d send by the server socket=%d, client port=%d, ip=%s\n",counter,socket_handle,Clientport,inet_ntoa(thread param.cli_addrth.sin_addr));
//printf("***Response %3d send by the server socket=%d\n",counter,socket_handle);
}
//keeping track how many packets this specific client sends
counter++;
}
return 1;
}


question -- multi threading is not working can any body tell why it is so?
-- modified at 0:44 Thursday 5th July, 2007
AnswerRe: Multi threading in c++ Pin
Jürgen Jung1-Jul-07 21:26
Jürgen Jung1-Jul-07 21:26 
QuestionHow to Deploy Presentation Layer and COM + in two servers? Pin
Sylvester george27-Jun-07 19:04
Sylvester george27-Jun-07 19:04 
Questionverify MS Index server from code Pin
kaushik_Manoj26-Jun-07 18:47
kaushik_Manoj26-Jun-07 18:47 
QuestionWhy TLS(Thread Local Storage) can not be used in COM Pin
jsjwql26-Jun-07 16:58
jsjwql26-Jun-07 16:58 
AnswerRe: Why TLS(Thread Local Storage) can not be used in COM Pin
Roger Stoltz27-Jun-07 1:56
Roger Stoltz27-Jun-07 1:56 
QuestionSQL XML 3 BulkLoad Error Pin
Panchal Hardik25-Jun-07 2:29
Panchal Hardik25-Jun-07 2:29 
AnswerRe: SQL XML 3 BulkLoad Error Pin
Dave Kreskowiak25-Jun-07 4:05
mveDave Kreskowiak25-Jun-07 4:05 
QuestionCatching events from C# COM in VC++ client Pin
Gakk22-Jun-07 3:57
Gakk22-Jun-07 3:57 
QuestionProblem with dll file Pin
Natarajasivan22-Jun-07 0:45
Natarajasivan22-Jun-07 0:45 
Question&amp;quot;Server busy&amp;quot; since changed to VC2005 SP1 [modified] Pin
howieh21-Jun-07 20:47
howieh21-Jun-07 20:47 
Questionadd Activex Object Pin
dhatchu21-Jun-07 16:27
dhatchu21-Jun-07 16:27 
QuestionPrinterProperties Pin
moon_stick21-Jun-07 5:46
moon_stick21-Jun-07 5:46 
AnswerRe: PrinterProperties Pin
moon_stick21-Jun-07 22:41
moon_stick21-Jun-07 22:41 
QuestionStateable Web application using COM+ Pin
Babak Ansari19-Jun-07 23:38
Babak Ansari19-Jun-07 23:38 
QuestionReleasing a com interface Pin
john563219-Jun-07 18:31
john563219-Jun-07 18:31 
AnswerRe: Releasing a com interface Pin
Steve S20-Jun-07 1:49
Steve S20-Jun-07 1:49 
AnswerRe: Releasing a com interface Pin
Erik Midtskogen20-Jun-07 12:36
Erik Midtskogen20-Jun-07 12:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.