C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-26-2007, 04:26 AM   #1
Registered User
 
Join Date: Sep 2004
Posts: 78
Sending 2 things simultaniously to same client.

Hi, I'm having trouble figuring out how to do two things "simultaniously" over the same connection. Say I want to send 2 files to the same client or send 1 file and some text messages. The problem is that I use the send function to do both so I can't make sure that the client recv doesn't mix the file info with the text message (I'm using winsock). An example of the behavior I need is something similar to msn messenger (or any other chat software), there you can chat and send a file at the same time. Since I'm sending both messages and files with the send function, there is no way for the client recv function to know the difference because all it does is receiving the next bytes available over the connection.

I would really appreciate any help I can get because I don't see any solution at all.
antex is offline   Reply With Quote
Old 03-26-2007, 04:46 AM   #2
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,332
You can wrap your messages in some internal protocol
((MesType,MesLen,MesBody))
and parse these buffers on the receiver side applying actions according to MesType
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is online now   Reply With Quote
Old 03-26-2007, 05:30 AM   #3
Registered User
 
Join Date: Sep 2004
Posts: 78
Ok thanks. Is it a bad idea to let the first or first few bytes received from each call identify the type, or is that good enough for most purposes? But what if not all info gets extracted in one call, due to some connection problem or some kind of buffer problem, then the next piece of information won't be the identification bytes. How do I solve this? I really don't understand internal socket buffers or whatever they are called.

Last edited by antex; 03-26-2007 at 05:36 AM.
antex is offline   Reply With Quote
Old 03-26-2007, 06:03 AM   #4
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,332
Define some pattern for message start and message end (called start marker and end marker)
in my sample it was "((" and "))"
check for these markers before you start parsing the rest and after you finished parsing

if markers don't match - start scanning the stream till you find the start marker...

It you use TCP and not UDP you should not have problems with loosing data or receiveing unordered data...
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is online now   Reply With Quote
Old 03-26-2007, 06:29 AM   #5
Registered User
 
Join Date: Sep 2004
Posts: 78
Thank you very very much!
antex is offline   Reply With Quote
Old 03-26-2007, 01:37 PM   #6
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
Quote:
Originally Posted by antex
Ok thanks. Is it a bad idea to let the first or first few bytes received from each call identify the type, or is that good enough for most purposes? But what if not all info gets extracted in one call, due to some connection problem or some kind of buffer problem, then the next piece of information won't be the identification bytes. How do I solve this? I really don't understand internal socket buffers or whatever they are called.
Why not just make another connection to the host? Imagine trying to have three conversations on a single phone line. You could come up with some complicated protocol to allow multiple people to all talk on the same line, but WHY?
brewbuck is offline   Reply With Quote
Old 03-26-2007, 10:59 PM   #7
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,332
Quote:
Originally Posted by brewbuck View Post
Why not just make another connection to the host? Imagine trying to have three conversations on a single phone line. You could come up with some complicated protocol to allow multiple people to all talk on the same line, but WHY?
BTW - I think that is what Messagenger ICQ etc do, You can check the number of open ports on your comp when you start simple conversation in Messager, and compare it to the number of open ports when the file transfer starts... 1 port should be added to the list
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is online now   Reply With Quote
Old 03-29-2007, 11:43 PM   #8
Registered User
 
Join Date: Sep 2004
Posts: 78
Well, I didn't think about that at all, but that seem to be a good option and far easier to program too. Thank you both for your replies! I really appreciate you help!
antex is offline   Reply With Quote
Old 04-16-2007, 11:44 AM   #9
Malum in se
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 3,188
You could try sending the text as OOB data, which is handled seperately from the normal data stream.
abachler is offline   Reply With Quote
Old 04-16-2007, 01:37 PM   #10
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,768
Quote:
Originally Posted by abachler View Post
You could try sending the text as OOB data, which is handled seperately from the normal data stream.
A Google search for "TCP OOB" turns up zillions of examples why using OOB transmission is a bad idea, not universally supported, not guaranteed to work, etc.
brewbuck is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Web server authentication using C client program by sending user name and password vikass C Programming 2 07-24-2008 06:05 AM
server client problem rudeboy Networking/Device Communication 5 05-17-2008 12:41 AM
sending binaries files between server and client nacho4d C Programming 12 01-31-2008 01:54 AM
Sending messages with few fields between client and server? nkn C Programming 2 11-23-2007 02:10 AM
Server Client Messaging Program X PaYnE X Networking/Device Communication 3 01-04-2004 05:20 PM


All times are GMT -6. The time now is 12:31 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22