|
hi.......
how to write multithreading + winsock using structure in vc++.......
i have tried to some extend but i want some good idea..... anybode plz help...
if possible plz send a proper code too..
thaks in advance
yamuna
-- modified at 8:16 Wednesday 18th January, 2006
|
|
|
|
|
R u using raw-socket ??
Vikas Amin
Embin Technology
Bombay
|
|
|
|
|
|
hello...
i'm not using raw socket..
i'm new to this area..
hope u can understand what i need.....
plz try to help me with a code..
thanks
yamuna
-- modified at 9:03 Wednesday 18th January, 2006
|
|
|
|
|
yamunasenthilvel wrote: i have tried to some extend...
What have you tried, and what results did you achieve?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
// multithread.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <afxtempl.h>
#include <winsock2.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
DWORD WINAPI sthread(LPVOID param);
DWORD WINAPI cthread(LPVOID iparam);
int startserver();
int stopserver();
HANDLE hthread;
HANDLE hstopevent;
CArray<handle,handle> threadarray;
DWORD WINAPI cthread(LPVOID iparam)
{
printf(" client thread");
return 0;
}
DWORD WINAPI sthread( LPVOID param)
{
SOCKET sserver,sclient;
SOCKADDR_IN sadd;
HANDLE hcthread;
DWORD sthreadid;
int lenaddr;
sserver = (SOCKET &)param;
if ( listen(sserver, 5 ) == SOCKET_ERROR )
{
printf( "Error listening on socket.\n");
return 0;
}
// Accept connections.
printf( "Waiting for a client to connect...\n" );
while (1)
{
lenaddr = sizeof(sadd);
sclient = accept(sserver,(struct sockaddr*)&sadd, &lenaddr);
if( sclient == INVALID_SOCKET)
{
printf("Accept Failed");
break;
}
printf("Client Connected");
printf("Accepted client: %s: %d\n",inet_ntoa(sadd.sin_addr), ntohs(sadd.sin_port));
hcthread = CreateThread(NULL,0,&cthread,(LPVOID)sclient,0,&sthreadid);
if(hcthread == NULL)
{
printf("Error in thread creation");
}
else
threadarray.Add(hcthread);
}
return 0;
}
int startserver()
{
SOCKET sock;
SOCKADDR_IN saddress;
WSADATA wsadata;
DWORD threadid;
DWORD result;
int iAddrSize;
iAddrSize = sizeof(saddress);
result = WSAStartup(MAKEWORD(2,2),&wsadata);
if(result != 0)
{
printf("Startup failed");
}
sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(sock == INVALID_SOCKET)
{
printf("invalid socket");
}
saddress.sin_family = AF_INET;
saddress.sin_addr.s_addr = inet_addr("10.95.10.217");
saddress.sin_port = htons(1023);
if(bind(sock,(PSOCKADDR)&saddress,sizeof(saddress))== SOCKET_ERROR)
{
printf("Error in binding");
}
hthread = CreateThread(NULL,0,&sthread,(LPVOID)sock,0,&threadid);
if(hthread == NULL)
{
printf("Error in thread creation");
return 1;
}
return 0;
}
int stopserver()
{
for(int ccount = 0;ccount <= threadarray.GetUpperBound();ccount++)
{
printf("client closing %d",ccount);
CloseHandle(threadarray.GetAt(ccount));
}
CloseHandle(hthread);
return 0;
}
void main()
{
hstopevent = CreateEvent(NULL,TRUE,FALSE,"network");
startserver();
stopserver();
getch();
}
this what i have done..
|
|
|
|
|
I would nix the extra thread and focus my attention on getting the server/client communication working. Then, and only then, should you attempt to add the complexity of additional threads.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
communication is proper.. one thing is when client is disconnected i should get "client disconnected". particular number of client can be connected.....so when one client disconnect then it should be intimated and its IP address should not display on server..
no need for additional threads i think..
as i said i'm sorry i'm new to this area.
yamuna
|
|
|
|
|
yamunasenthilvel wrote: how to write multithreading + winsock using structure in vc++.......
Just a ?, why are you going after multithreading ! have a look at this :- http://www.codeproject.com/internet/ndk.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi,
There
In my project(Visual C++ project, there is a Editbox in a form,
I would like to copy a segment of selected text in the Editbox into clipboard by pressing Ctrl-C as we would with MS-Word. I wonder if this is possible, and how to achieve this.
Thanks
Yong Chen
cy163
-- modified at 7:57 Wednesday 18th January, 2006
|
|
|
|
|
if you have a CEdit (MFC) and select a part of the edit content, then Ctrl+C will automatically copy the selection into the clipboard...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Tox, you were right to have posted that message. Even I wondered why had you went to that level down, but I too am Feeling the same. There is somebody who is giving EVERYBODY a low rating (whenever they get 5). I do not understand why someone would do this. But it HURTS MAN. Believe me. It hurts a lot. You take your time to analyse the problem, and then you give the best possible solution that you can. The one who asked the question thanks you and gives a 5, so does some people... After some time, the rating comes down for no reason. I think rating must be given by the person who asks the question or whomever is involved in the conversation only. It hurts. Or just remove this rating thing. We are ready to help for no rating. Not a problem. I could understand what Toxcct felt, now. It hurts man. I have joined CP recently and started helping ppl very recently. Why would someone have a problem when I get a 5 rating? I know I have to use profanity and behave myself in this forum, with a bundle of real genius people...
If this is wrong too, i will delete this. Not a problem. I will keep to contribute whatever I know, no matter if it is a penny or two. If it helps someone, I am happy. Give me zero rating, I dont care until the person gets helped and tells me that.
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
What does all of this have to do with Ctrl+C and the clipboard?
Quite worrying so much about votes. They're next to meaningless in my opinion. Never understood why people get so hung up on such unimportant things. At the end of the day, it doesn't matter.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
|
Maximilien wrote: you don't mind if I vote you a 5 ?
Any way who voted you 3 and Mr David 1... any way my 5 fit the all
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
DavidCrow wrote: What does all of this have to do with Ctrl+C and the clipboard?
Extremely sorry about that.
DavidCrow wrote: They're next to meaningless in my opinion.
Thanks for the concern David, I have understood it is meaningless. really. I continue to contribute as much as possible without worrying about votes and all that stuff.
Regards,
Rajesh R. Subramanian.
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
Rajesh,
You said "I know I have to use profanity and behave myself in this forum".
Personally, I don't object to a little profanity from time to time, but others might.
I offer you the best possible vote.
Shraddhan
|
|
|
|
|
Thank you so much for your reply.
In my project, I cannot use CEdit class. I have to use CFormView class and EditBox control.
Do you mean that it is impossible to use Ctrl-C to copy a segment of selected text to clipboard in my case.
Yong Chen
|
|
|
|
|
Hi,
I require high precision data types in order to store fractional values up to say around 64 decimal places (arbitrary would be good also), i.e. 0.999999991228342783642783647826347263487234... etc. The double datatype is insufficient, and the long double is double in disguise by current compiler standards (why this is so I'm not sure). So to overcome this problem I serched the internet high and low for a C++ class based high precision data-type and found, amongst others, QD (quad-double) which would be fine for my purposes. (you can find this on a goodle search)
When I set up a standard console application and then try to include all the files everything works fine and everything links, so long as i add the qd progect to my solution and alter program dependencies so that my main app depends on the qd vcproject. The program quite happily churns out high precision results using the "qd_real" data type class.
However, if i try to get the same class to work in an MFC console application it doesnt want to play. At build time I get very strange results such as:
c:\Documents and Settings\Paul\Desktop\HP\qd-win-2.1.48b\qd-win-2.1.48\include\qd\qd.h(258): error C2059: syntax error : ')'
c:\Documents and Settings\Paul\Desktop\HP\qd-win-2.1.48b\qd-win-2.1.48\include\qd\qd.h(151): error C2059: syntax error : 'newline'
c:\Documents and Settings\Paul\Desktop\HP\qd-win-2.1.48b\qd-win-2.1.48\include\qd\qd_inline.h(49): error C2065: 'a' : undeclared identifier
c:\Documents and Settings\Paul\Desktop\HP\qd-win-2.1.48b\qd-win-2.1.48\include\qd\qd_inline.h(54): error C2084: function 'qd_real::qd_real(int)'
already has a body
c:\Documents and Settings\Paul\Desktop\HP\qd-win-2.1.48b\qd-win-2.1.48\include\qd\qd.h(258): error C2143: syntax error : missing ')' before ';'
These errors didn't occur in the standard console implementation.
Furthermore, if I take the #include "qd/qd.h" and put it before the #incude "stdafx.h" the application compiles, but then the program complains that it doesn't know what qd_real class is if i try to instantiate one in main().
I've also tried placing the #inlcude "qd/qd.h" in the stdafx.h files, but still it comes up with the errors.
Does anybody have some sort of idea what is going on?
Thanks.
Paul
|
|
|
|
|
sntpaul wrote: I require high precision data types in order to store fractional values
i do to, and i need to basic functions provided on the type, such as cosine, logarithm, square root, etc...
looking for the answers with much interest
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
please see my reply to sntpaul's post - it may help you both (I found a 'windows' version)
'g'
-- modified at 8:00 Wednesday 18th January, 2006
|
|
|
|
|
I dont know where you got that version from - I couldnt find it, and the one previous to that, is a unix build environment and its very late at night down here, so 'scuse me for not building a library from it ...
- there's a 'windows' version here :-
http://www.cs.berkeley.edu/~yozo/[^]
(look for qd-win-2.1.19.zip)
this may improve things ... (my suggestion would have been to build qd as a seperate library, hopefully the win version does this and its more use)
'g'
-- modified at 7:54 Wednesday 18th January, 2006
|
|
|
|
|
Thanks,
I'll see what I can do with this
|
|
|
|
|
Hi g,
Thanks for the link I have seen this page before and it is in fact the windows version of QD that wouldn't work with MFC when i tried to mix the two pieces of code.
However, instead i did something which i hadn't previously tried. I used the ARPEC library windows download and that, after a bit of jiggery pokery here and there, works well.
Thanks for your help... without you directing me to that link i may well have been pulling my hair out by now, or sitting miserably in a corner !
Paul
|
|
|
|
|
i want to know/get the file name by clicking the icon .......please frnds help me out...mail me with the answer Priyasloka.Arya@honeywell.com/tikiarya@rediffmail.com
thank you
regards
tiki
|
|
|
|