|
... and to receive the message you do:
const int MAX_BUFF = 1024;
char buffer[MAX_BUFF];
recv(theSocket,&buffer, MAX_BUFF, MSG_OOB);
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Hi,
I think that highly depends on your protocol.
I was collecting some ideas about networking and Gnutella protocol (a P2P filesharing application). Gnutella is interesting here, because it uses line buffered data stream (e.g. HTTP handshaking) and also block buffered data (e.g. binary Gnutella protocol). The article can be found at: Programming a Gnutella Client, part II: network core
Let me know if it helps, I'm learning...
|
|
|
|
|
Well, I don't think it was the right answer
But, I just wanted to know how it worked... I'm still preparing how I will build my chat program!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Rickard Andersson wrote:
I'm still preparing how I will build my chat program
Have fun!
I'm on irc.p2pchat.org, if you wanna test my chat application.
|
|
|
|
|
Hi.
Okay. Basically, the program will be a client and a server. If it is connected to any other client/server, than the connect feature will be disabled.
As for the message, I plan to send and receive message and and forth. As for I/O mode and I/O model, I will use the simple WSAAsynSelect (non-blocking) model since it uses the Windows (MFC) messaging system.
Kuphryn
|
|
|
|
|
|
From heart:
char szMsg[] = "A message";
long nMsgSize = strlen(szMsg);
long nSize = nMsgSize;
nSize = htonl(nSize);
send(sock, &nSize, sizeof(long), 0);
send(sock, szMsg, nMsgSize, 0); This example uses a four byte length header.
Now, when reading
long nSize;
recv(sock, &nSize, sizeof(long), 0);
nSize = ntohl(nSize);
char *pszMsg = new char[nSize + 1];
recv(sock, pszMsg, nSize, 0);
pszMsg[nSize] = '\0'; pszMsg will now, hopefully , contain your message.
|
|
|
|
|
Wow. Nice!
Thanks.
Okay. I want to walk through your code one part at a time.
1)According to the above, you did not use "4" as byte count anywhere in the code. You used a long variable as the static size of the first four bytes. Is that correct? If yes, what is the advantage to using sizeof(long) stead of just this:
// char fourbyte[4];
//send(sock, fourbyte, 4, 0);
2) You used the function htonl() to convert to "net byte order." Jones and Ohlund dedicated a section or so to four functions that converts between byte order (host byte order to/from network byte order). Can you explain why we eed htonl()?
Dire.Wolf posted another technique using WSARevc(). Here is a link to the code.
http://www.gamedev.net/community/forums/topic.asp?topic_id=93771
I will try both your technique and the one Dire.Wolf mentioned. Although, your technique is more flexible in the sense that we do not need to know the size of the data after the first four byte. The size of the data after the first four byte will be calculated and then a character array is created at that size. Very nice!
Thanks again,
Kuphry
|
|
|
|
|
Note from MSDN
int recv(
SOCKET s,
char FAR *buf,
int len, //sizeof buffer NOT amount to read
int flags
);
"For connection-oriented sockets (type SOCK_STREAM for example), calling recv will return as much information as is currently available—up to the size of the buffer supplied"
Correct me here if I am wrong but;
So if ALL the info is not available at the time of the call it will return with less. The next time you call recv() you will be expecting a size amount but the remainder of the previous string will be there. Splat!
while(iRecv < iLen)
iRecv+= recv(socket ,&sBuffer[iRecv] ,iLen, FLAGS); //this could work
Now what happens if the amount in the socket is greater than the buffer size (ie Next string is there as well)?
recv() returns an error, WSAEMSGSIZE and waits until a buffer large enough is supplied. But you can't get a buffer large enough as you need to read from the socket to get the size of the second msg.
|
|
|
|
|
Hi.
I would like to know how to enable/disable a specific view inside a split window. For example, let there the split window comes default with three visible windows.
-----
View1
-----
View2
-----
View3
-----
If the user select an option in the menu to hide view2 or maybe a calculated needs to disable view2, is there a way to do that in MFC?
Most important that is the entire window must be redrawn. I am not sure how to redraw multiviews inside of main in SDI architecture.
Thanks,
Kuphryn
|
|
|
|
|
Hi
Could anyone kindly show me how to remove the last character in CString pls
I've tried Delete and Remove but it didnt' work
Thanks
|
|
|
|
|
Delete should work
CString cs = "String";
cs.Delete(cs.GetLength()-1);
|
|
|
|
|
Hi
Your solution just doesn't work. But thanks anyway.
Cheers
|
|
|
|
|
tcuong wrote:
Could anyone kindly show me how to remove the last character in CString pls
m_string=m_string.Left(m_string.GetLength()-1);
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Hi
This work perfectly
Thanks for assistant
|
|
|
|
|
how can i make my .cpp file member of my project?
|
|
|
|
|
dhon wrote:
how can i make my .cpp file member of my project?
From the "Project" menu, take "Add to Project" and then "New"
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
what does it take to make a borderless splitter window in VC6? I want to put a few views one next to each other, without the "border" between them.
is there any "simple" way to do it (meaning, one call does the work) or should I derive a class from CSplitterWnd, change a few internal member variables (sizes & colors), and force them to draw a splitter which blends with the background?
thanks.
|
|
|
|
|
Views are just windows, so you can arrange them in what ever way pleases you. If it works best for you to use CSplitterWnd, then do so; it is not too difficult to create a derived class that will draw the splitters in any way you choose. Do a search here for splitter; I think you'll have several articles to choose from.
--------
I don't think that I'm a sell-out but I do "Enjoy Coke!"... -- Bloodhound Gang, The Inevitable Return Of The Great White Dope
|
|
|
|
|
How I know what my screen mate move pass each window component (such as edge of window..etc.) ?
Thank a lot
|
|
|
|
|
What is a screen mate?
(and if you reply "that square thing in front of you mate", i will hurt you )
--------
I don't think that I'm a sell-out but I do "Enjoy Coke!"... -- Bloodhound Gang, The Inevitable Return Of The Great White Dope
|
|
|
|
|
Shog9 wrote:
and if you reply "that square thing in front of you mate", i will hurt you
LOL
Seriously I think he means some kinda funny desktop program that does fun stuff, like walk into the screen randomly and strip or something.
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Screen mate?
Is that some kinda fancy desktop application?
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
yes. sometime called "desktop toy"
the screen mate will move on desktop and do something fun
I want to know what's component that screen mate move over (such as edge of window app)
Thank a lot
|
|
|
|
|
The personnel manageress in my company has a very cute penguin screen mate!
Maxwell Chen
People say "No news is good news". Then, no code is good code!?
|
|
|
|