Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old March 14th, 2004, 03:38 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Agh! that's some socket bug I havn't been able to fix. What's happening is the client is receiving two messages from the server at once and sticking them in the same input string. So say it sends 'CON:mark' and then 'USERLIST' right after, the client will end up concatenating them to 'CON:markUSERLIST'. It sends that off to the parser which gets rid of 'CON:' and what it left is 'markUSERLIST'. I have a hard time reproducing it on my Mac, sometimes it ends up happening when a 5th or 6th client connects. Any ideas on how to keep it from doing this? Is there anyway to tell recv() where the end of one message is? I've heard something with newlines when it comes to buffered input.

Last edited by XxChris : March 14th, 2004 at 03:41 PM.

Reply With Quote
  #17  
Old March 15th, 2004, 04:03 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No ideas? Any socket gurus?

Reply With Quote
  #18  
Old March 16th, 2004, 02:00 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Xx,
Not sure how else to do it but what about constructing a header and putting that at the front of each message? The header will start with a sequence to identify it, a start of message pointer and length of message.

Code:
Characters in message block:
0------2-----------4-------- 6---n--------------- n+len
--------------------------------------------------------
|Header|Msg Start=n| Msg Len|..... |Actual message......|
--------------------------------------------------------
where n is actually the end of header. 
The header start sequence could be one or two characters like !#.

Then all you do is read the first 6 bytes, check them, read (len -6) characters, split the remaining head from the actual message and process the message. I've included a message start pointer to allow for a variable length of header - that way you can expand your protocol in the future.
You could consider adding a "type" character in the header to indicate what the contents of the packet are e.g. message or control.

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : March 16th, 2004 at 02:02 AM. Reason: Spelt my name wrong:D

Reply With Quote
  #19  
Old March 16th, 2004, 03:13 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Quote:
Originally Posted by Grim Archon
Xx,
Not sure how else to do it but what about constructing a header and putting that at the front of each message? The header will start with a sequence to identify it, a start of message pointer and length of message.

Code:
Characters in message block:
0------2-----------4-------- 6---n--------------- n+len
--------------------------------------------------------
|Header|Msg Start=n| Msg Len|..... |Actual message......|
--------------------------------------------------------
where n is actually the end of header. 
The header start sequence could be one or two characters like !#.

Then all you do is read the first 6 bytes, check them, read (len -6) characters, split the remaining head from the actual message and process the message. I've included a message start pointer to allow for a variable length of header - that way you can expand your protocol in the future.
You could consider adding a "type" character in the header to indicate what the contents of the packet are e.g. message or control.

Grim


By knowing the size of the "packet" you can ignore any rubbish in between and by specifying the length up-front you can include any "control" characters you like in the message.

I think you need something like this so that your receiver does not rely on it's previous receive state to accurately decode the subsequent messages. To get more sophisticated, include a simple checksum in the header so that during a recovery when you scan the incoming data for the start of packet you can be sure that the sequence really was the start of packet.

Grim

Reply With Quote
  #20  
Old March 16th, 2004, 02:23 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hmm it sounds like it will take quite a bit of work to implement this, but it's definitly something I will look into. Thanks.

Reply With Quote
  #21  
Old March 16th, 2004, 02:48 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
To keep it simple and trial it you can just include the message length as the first byte and limit messages to max 255 characters. You only have a one byte header. (So maximum packet size is 256)

But that builds in limits and does assume that every packet is received correctly (i.e. there is never a bug in the sender program)

Reply With Quote
  #22  
Old March 16th, 2004, 04:35 PM
XxChris XxChris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 217 XxChris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'll probably take the first idea for the experience. Thanks for your help .

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Chat Server Version 0.1


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway