473,473 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

TCP message

2 New Member
I am currently trying to send strings across a tcp connection between two computers. My problem is that python receives ALL the strings together instead of receiving each string as I send it. I want to be able to receive each string separately and parse it before receiving the next one. Will I have to split the string on the receiving end or is there something simple that I'm missing?

[server]
Expand|Select|Wrap|Line Numbers
  1. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
  2.                          socket.IPPROTO_TCP)
  3. sock.connect((comp[0], 7777))
  4. sock.send(string1)
  5. sock.send(string2)
  6. ...
  7. sock.shutdown(socket.SHUT_RDWR)
  8. sock.close()
[client]
Expand|Select|Wrap|Line Numbers
  1. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 
  2.                        socket.IPPROTO_TCP)
  3. sock.settimeout(10)
  4. sock.bind(('', 7777))
  5. sock.listen(1)
  6. conn, addr = sock.accept()
  7. while(1):
  8.    message = conn.recv(1024)
  9.    if not message:
  10.       break
  11.    <parse message>
  12. sock.shutdown(socket.SHUT_RDWR)
  13. sock.close()
Jan 17 '08 #1
1 1360
jlm699
314 Contributor
Expand|Select|Wrap|Line Numbers
  1. sock = socket.socket(socket.AF_INET, 
  2.    message = conn.recv(1024)
  3.  
When you specify a byte size to receive it will try to receive as much as is available at that time. Unless you know the exact size of your messages, you'll need to rely on client-side parsing.

A good way to achieve this is to append some kind of end tag to your messages (which is what I've done in the past) for example, "MSG_RSP"
Jan 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Hugh Welford | last post by:
Hi Using WIN XP and FP2000 Using CDO.message to out put a message from my site, I get the following error message 8004020f from using the code:- strsql = "SELECT * FROM details WHERE patid...
8
by: Brian Keating EI9FXB | last post by:
Would I be correct in saying that the only way to get a user message into a Windows form would be to use P/Invoke with Message? Of is there some part of the .NET API that I am totally un aware...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
2
by: Microsoft News | last post by:
What I have is a message box that pops up. It is another browser window. The code is a general function that you pass message, title and a key to. The box works great except, that if you are on a...
0
by: ronscottlangham | last post by:
I am working on a custom WCF EndpoingBehavior that will modify the messages coming in and out of my Service. I am having an error related to the modification of the message in the...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
3
by: Steven Allport | last post by:
I am working on processing eml email message using the email module (python 2.5), on files exported from an Outlook PST file, to extract the composite parts of the email. In most instances this...
0
by: Philluminati | last post by:
I have a Perl SOAP Server which returns this SOAP Message when invoked: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance"...
2
by: bernd | last post by:
Hi netties, posted this in a different group already, which seems to be inappropriate. I create a message queue with msgget(), sent a 5-byte message to it with msgsnd() and try to receive the...
2
by: forums_mp | last post by:
Facing a design problem here and I'm not sure how to solve this. The system consists of bi-directional communication between a subject communicating with two (at least for now ) listeners. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.