|
hi, guys,
In my current Winsock-based TCP program, on the client side, after I send my request data packet to the Server side using the send socket function, I attempt to get the socket status to see if it has something to read using the select function, and the select function always return 0 meaning the time limit expired on some users' computers, but it's just fine on another users' computers.
Why? Does anybody can tell me why and how to fix it? Thanks!
here's the code...
//...
SOCKET sckClient = socket(AF_INET, SOCK_STREAM, 0);
int nOne = 1;
setsockopt(sckClient, IPPROTO_TCP, TCP_NODELAY, (char *)&nOne, sizeof(int)); // just_say_no
struct sockaddr_in addr_to = { 0 };
//...
connect(sckClient, (struct sockaddr *)&addr_to, sizeof(addr_to));
char *buf;
//...
send(sckClient, (const char *)((char*)buf), nDataToSend, 0);
int nRetCode = ::select((int)sckClient + 1, &fdsRead, NULL, NULL, &tvTimeOut);
if (nRetCode==0 )
{ //ERROR: the time limit expired
//Here's the problem! some computers meet the error, but some don't! WHY???
}
recv(sckClient,(char *)buf,nDataToRead, 0);
//...
|
|
|
|
|
Does the second system receive the packets okay?
Kuphryn
|
|
|
|
|
With this message I would like to appologise to everyone that tried to download my article about the chat program. I will post it tonight and it will work. I am sorry for the dissapointment. It was a problem with the attachement.
gabby
|
|
|
|
|
Hi guys,
I'm looking for some ASCII characters that can be used as some sort of separator delimiters. For example, I have few string fields I'd concatenate into one long string and put into CListBox. Then I'd need to be able to retrieve the string and break them up back to original fields. So ideally, those separators should be invisible on the display.
(S)Hi, The(E)(S) Code (E)(S)Project is Cool!(E)
would display as
Hi, The Code project is Cool!
where (S) is invisible start delimiter and (E) is the end delimiter.
I tried "Unit Separator" and "Record Separator" (0x1F and 0x1E respectively), they work fine in Windows XP, where these are not displayed. However, when I moved the app to Windows 98, they are shown visibly as rectangle blocks.
I'm wondering if the difference is due to the uses of unicode and not.
If so, are there any ASCII I can use for my purpose?
Thanks alot!
|
|
|
|
|
There are no characters you can use for non-UNICODE, the ANSI-fonts are supposed to show a "dummy"-character for codes they don't define. So, yes, you are right, this is a question of UNICODE and non-UNICODE
What I would have done would be to create an owner-drawn listbox (which is not at all difficult once you've done it once or twice, if you hesitate). There, I would have split the strings according to some of me defined delimiter.
|
|
|
|
|
Thanks alot Johan,
I'm trying to think very hard to how Owner Draw on CListCtrl (it's actually CCtrlList I'm using) can help me. But you were right. Since I haven't done this before, I have trouble to figure out a way. I'd really appreciate some hints here
Do you mean that I could somehow display the string and "hide" those delimiters? My understanding to Owner Draw is being able to draw images and customise text. I don't really know how it can help in my case.
Thanks again
|
|
|
|
|
Consider a listbox containing the string
Alpha|beta
In a draw handler, we get the string, and want to use the bar as a delimiter.
CString left;
CString right;
int found = str.Find( _TCHAR( "|" );
if( found != -1 )
{
left = str.Left( find );
right = str.Right( str.GetLength() - ( found + 1 ) );
dc->TextOut( left, ...
dc->TextOut( right, ...
}
You might want to check the articles in http://www.codeproject.com/listctrl/[^], I notice that the very first one discusses owner-drawing.
|
|
|
|
|
Thanks again, Johan,
As I understand, it is to use the Owner Draw to customise the display of the text on list box. In your example, the text Alpha|beta can get shown as Alpha beta. And so supposedly, when I retrieve the text from the list box using GetText() , it should still return Alpha|beta? The actual content is not changed, just displayed differently on screen? Is it how this works?
Thanks.
|
|
|
|
|
|
Hi
I would like to know about "lstrcpy" function.Please give me at least on example so that I could understand and use.
rajesh
|
|
|
|
|
LPCTSTR pszString = "Hello";
TCHAR szCopyTo[100];
::lstrcpy(szCopyTo, pszString);
Result = szCopyTo = "Hello"
|
|
|
|
|
Better to use lstrcpyn to avoid buffer overflows
TCHAR chBuffer[512]= {0} ;
lstrcpyn(chBuffer, "abcdefghijklmnop", sizeof(chBuffer) -1 ) ;
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I'm trying to add two buttons on an IE toolbar and then to resize the first one:
TBBUTTON Button[2];
ZeroMemory((void *)Button, 2*sizeof(TBBUTTON));
Button[1].idCommand = IDM_SECOND;
Button[1].fsState = TBSTATE_ENABLED;
Button[1].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT;
SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)(Button+1));
Button[0].idCommand = IDM_FIRST;
Button[0].fsState = TBSTATE_ENABLED;
Button[0].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE;
SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)Button);
TBBUTTONINFO tbbut;
tbbut.cbSize=sizeof(TBBUTTONINFO);
tbbut.cx=200;
tbbut.dwMask=TBIF_SIZE;
SendMessage(m_hWnd, TB_SETBUTTONINFO, IDM_FIRST, (LPARAM)&tbbut));
but it seems that the last line doesn't have any effect at all. Replacing there IDM_FIRST with IDM_SECOND will, on the other hand, correctly resize the second button
Any advice?
rechi
|
|
|
|
|
Hi all;
I would like to express my most heart-felt thanks to all you folks who have helped me in getting acquainted with Visual C++. Now i'm ok. However, this does apply to Mr Prakash who has been very rude and useless to me!
Thanks folks
Krugger
|
|
|
|
|
datastruct wrote:
However, this does notapply to Mr Prakash who has been very rude and useless to me!
Were here to help, even Mr Prakash, although sometimes the help you give is not always the help you receive. (Some twisty Aes-Sedai wording there).
Roger Allen - Sonork 100.10016
Strong Sad: I am sad I am flying
Who is your favorite Strong?
|
|
|
|
|
datastruct wrote:
However, this does apply to Mr Prakash who has been very rude and useless to me!
Of the 21 posts that you have made to date, only four of those have been replied to by Mr.Prakash. Of those four, I've not found any that I would consider rude. Perhaps you have extremely thin skin, or your definition of rude differs from mine. I suspect it's just a language barrier issue.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
My guess he was refering to the post where MrPrakash refused to give him the registration key for the skinmagic library.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Perhaps, but that's far from rude. That's simply saying that "I can't give you something that you have not paid for." A lot of folks are all to quick to share registration keys.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I totally agree with you
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I'm not much of C++ programmer but am just putting together a very simple Dialog in Visual C++ 6.0.
It's one button and two Edit Boxes. From the first I get user input and the second I use for user feedback.
To the press button message handler I have added a function that is looping and for each loop I'd like to update the message in the second Edit Box.
The code looks something like this:
void CAppGUIDlg::OnButton1()
{
CAppGUIDlg::DoSomething();
}
void CAppGUIDlg::DoSomething()
{
int *string;
int max;
char *tmpStr = "";
int total = 0;
max = atoi(m_editStr1); //Get Edit Box 1 value
while (total < max )
{
//Do something with value from Edit Box 1
sprintf(tmpStr,"User message %i", total/1024);
UpdateData(false);
m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2
Sleep(200);
UpdateData(false);
}
}
What will happen is that Edit Box 2 will not be updated until the loop is finished. Is there a simple way to update it within every loop?
|
|
|
|
|
Either:
Do each thing in a different thread.
Or (more simply for this case)
Pump messages in your loop.
Change your loop to:
while (total < max )
{
//Do something with value from Edit Box 1
sprintf(tmpStr,"User message %i", total/1024);
UpdateData(false);
if(!PeekAndPump())
break;
m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2
Sleep(200);
UpdateData(false);
}
Then add this function to your class:
BOOL PeekAndPump()
{
MSG dlgMsg;
if (::PeekMessage (&dlgMsg, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetApp ()->PumpMessage ())
{
::AfxPostQuitMessage (0);
return FALSE;
}
return TRUE;
}
LONG lIdle = 0;
while (AfxGetApp ()->OnIdle (lIdle++));
return FALSE;
}
|
|
|
|
|
Exactly what I was hoping for. Thanksa lot Diddy!
|
|
|
|
|
No problem
|
|
|
|
|
if you want to send a message to an edit box just use SetDlgItemText function and you have only 2 parameters in MFC VC++.
gabby
|
|
|
|
|
Wont help.
If your looping around in that one function, you can do what you want to the other edit box, it wont redraw until you return from that function and contine to pump messages.
|
|
|
|
|