473,408 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

windows socket recv problem

Hi,

I m trying to receive a message on windows sockets using recv()
function.
The message is such that the first two bytes of the message represent
the length of the
message. Hence when trying to recv a message, i m doing 2 recv() calls.
The first recv() call receives the length of the message.
and the second recv() call receives the actual message.

The problem is that the first recv() instead of RECEIVING THE FIRST TWO
BYTES, receives the last two bytes of the message.

e.g unsigned char szTbuf[3];
recv(..., (char * ) szTbuf, 2, 0);

the above receives the last two bytes. and after receving it doesnt
come out.

Can any body help me please.

Sincere Thanx.

rgds,
Sandeep.

Jul 12 '06 #1
5 7771
sonu wrote:
e.g unsigned char szTbuf[3];
recv(..., (char * ) szTbuf, 2, 0);

the above receives the last two bytes. and after receving it doesnt
come out.

Can any body help me please.
Off topic and you probably send them in the wrong order, or your send
fails or gah.

Check return codes and/or post more complete code showing the error
[ideally though, move this to comp.programmer or something].

Tom

Jul 12 '06 #2

Tom St Denis wrote:
sonu wrote:
e.g unsigned char szTbuf[3];
recv(..., (char * ) szTbuf, 2, 0);

the above receives the last two bytes. and after receving it doesnt
come out.

Can any body help me please.

Off topic and you probably send them in the wrong order, or your send
fails or gah.

Check return codes and/or post more complete code showing the error
[ideally though, move this to comp.programmer or something].

Tom
Jul 12 '06 #3
sonu wrote:
I m trying to receive a message on windows sockets using recv()
function.
The message is such that the first two bytes of the message represent
the length of the
message. Hence when trying to recv a message, i m doing 2 recv() calls.
The first recv() call receives the length of the message.
and the second recv() call receives the actual message.
[Follow-ups set.]

This is probably not the best way to do this. Instead, loop on recv
until you have everything. Are you checking return values and error
codes? For example, you may need to care about WSAEMSGSIZE.

See the example use of recv() on MSDN
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/recv_2.asp>
Jul 12 '06 #4
sonu wrote:
Hi,

I m trying to receive a message on windows sockets using recv()
function.
The message is such that the first two bytes of the message represent
the length of the
message. Hence when trying to recv a message, i m doing 2 recv() calls.
The first recv() call receives the length of the message.
and the second recv() call receives the actual message.

The problem is that the first recv() instead of RECEIVING THE FIRST TWO
BYTES, receives the last two bytes of the message.

e.g unsigned char szTbuf[3];
recv(..., (char * ) szTbuf, 2, 0);

the above receives the last two bytes. and after receving it doesnt
come out.

Can any body help me please.
Read the Winsock FAQ (http://tangentsoft.net/wskfaq/) from top to bottom.
Some of it is probably not relevant to you (mostly that which deals with
16-bit Windows) but a great many of the rest is, and almost everything in
there is worth keeping in the back of your head.

If that doesn't help you, try a Windows-specific newsgroup like
comp.os.ms-windows.programmer.tools.winsock.

S.
Jul 12 '06 #5
But any case put the length at start , so if you not read all at once ,
you'll know how many bytes you have to read more
Arkady

"Clever Monkey" <cl**************@hotmail.com.invalidwrote in message
news:tO*****************@nnrp.ca.mci.com!nnrp1.uun et.ca...
sonu wrote:
>I m trying to receive a message on windows sockets using recv()
function.
The message is such that the first two bytes of the message represent
the length of the
message. Hence when trying to recv a message, i m doing 2 recv() calls.
The first recv() call receives the length of the message.
and the second recv() call receives the actual message.
[Follow-ups set.]

This is probably not the best way to do this. Instead, loop on recv until
you have everything. Are you checking return values and error codes? For
example, you may need to care about WSAEMSGSIZE.

See the example use of recv() on MSDN
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/recv_2.asp>

Jul 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: flupke | last post by:
Hi, I have a gui (made in wxPython) that enables a user to connect to a server and issue some commands. The problem occurs when i try to disconnect the client. It exits but it doesn't return to...
4
by: Bryan Olson | last post by:
Here's the problem: Suppose we use: import socket f = some_socket.makefile() Then: f.read() is efficient, but verbose, and incorrect (or at least does not play will with others);
1
by: Jason | last post by:
Hi, When using the socket module in Python 2.3 for windows, I'm having problems using socket.recv(int). The function works fine on its own, but when I attempt to encapsulate the socket...
4
by: Scott Robinson | last post by:
I have been having trouble with the garbage collector and sockets. Unfortunately, google keeps telling me that the problem is the garbage collector ignoring dead (closed?) sockets instead of...
10
by: groups.20.thebriguy | last post by:
socket objects have a little quirk. If you try to receive 0 bytes on a blocking socket, they block. That is, if I call recv(0), it blocks (until some data arrives). I think that's wrong, but I...
6
by: J Rice | last post by:
Hi, I feel like I should apologize in advance because I must be missing something fairly basic and fundamental here. I don't have a book on Python network programming (yet) and I haven't been able...
6
by: Abubakar | last post by:
Hi, lets say I have a connected SOCKET s. At some point in time, I want to know if the "s" is still valid, that it is still connected. Is there any API that I can give me this information? And...
10
by: Hendrik van Rooyen | last post by:
While doing a netstring implementation I noticed that if you build a record up using socket's recv(1), then when you close the remote end down, the recv(1) hangs, despite having a short time out...
2
by: Ali Hamad | last post by:
Hello All : A socket question from a networking newbie. I need to create a server that: 1) receive a message from client. 2) check that message and response to it. 3) the client get the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.