473,403 Members | 2,359 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,403 software developers and data experts.

winsock sending message error

196 100+
Hey im making a client/server program using winsocks, i have managed to connect the client to server but when i try to send a message from the client to the server, the message doesn't make it correctly.

I have tested the message before i sent it to see if its correct and the length, it seems fine but when i check it on the server prog its not even the same length, let alone readable.

This is the code im using to send the message (normal plain text) from the client

Expand|Select|Wrap|Line Numbers
  1. char buffer[256]; 
  2. ZeroMemory(buffer, 256);
  3. strcpy(buffer, ("This is the message"));
  4.  
  5. nret = send(theSocket, buffer, strlen(buffer), 0);
  6.  
This is the code im using to Receive the message, oh yer before this the server waits for a connection before reciving.

Expand|Select|Wrap|Line Numbers
  1. char buffer[256]; 
  2. int p;
  3.  
  4. nret = recv(listeningSocket, buffer, p, 0);
  5.  
  6.  
If found this code on jonnie winsock tutorial.
Nov 4 '07 #1
10 1979
weaknessforcats
9,208 Expert Mod 8TB
Did you test nret that the message was sent properly?

Did you test nret that the message was received properly?
Nov 4 '07 #2
chazzy69
196 100+
Hey sorry about getting back to the msg so late iv being away for a while, anyhow how would i go about testing nret for properly sent and properly received message.

Any help is appreciated
Nov 12 '07 #3
mac11
256 100+
send and recv should return the number of bytes sent or received or -1 (at least on my system) for error
Nov 12 '07 #4
chazzy69
196 100+
SO far i have just being using strlen(buffer) to find the length of the sent message and received message and they have being vastly different.

Can you give a quick example on how to return the number of bytes sent and received by send and recv?

Thanks for any help
Nov 13 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
Can you give a quick example on how to return the number of bytes sent and received by send and recv?
How about you post your calls to send and recv so I can see what you are doing. Then I can comment.

I assume you are aware that these functions return the number of bytes sent or received and that -1 means there was an error and in that case you need to call WSAGetLastError to see what the problem was.
Nov 13 '07 #6
chazzy69
196 100+
I have already posted my send and receive calls above (#1), also this program already has an error check for my send and receive:

Expand|Select|Wrap|Line Numbers
  1. if (nret == SOCKET_ERROR) {
  2.  
  3. return NETWORK_ERROR;
  4.  
Wondering if maybe trying to access the buffer the wrong way because i'm just trying to do this at the moment-
Expand|Select|Wrap|Line Numbers
  1. cout<< buffer<< "\n"<<strlen(buffer)<<"\n";
  2.  
This comes strait after receiving the message "
Expand|Select|Wrap|Line Numbers
  1.  nret = recv(listeningSocket, buffer, p, 0); 
"

Am i perhaps supposed to access buffer as part of nret????

Thanks for the help it appreciated.
Nov 15 '07 #7
chazzy69
196 100+
Ok i just checked and im getting nret= -1, so what am i supposed to do now???

thanks
Nov 15 '07 #8
chazzy69
196 100+
Is it possible that im getting an error because my recv is not waiting for the client to send its message?? if so how can i make it wait???


Thanks your help is greatly appreciated
Nov 15 '07 #9
mac11
256 100+
Let me first say that my comments are based on how sockets work in linux and I don't know if things will be different for you.

Ok i just checked and im getting nret= -1, so what am i supposed to do now???
check 'errno' to see why it failed - you'll have to #include errno.h if you didn't already

Expand|Select|Wrap|Line Numbers
  1.  cerr << "recv failed: " << strerror( errno ); 
Is it possible that im getting an error because my recv is not waiting for the client to send its message?? if so how can i make it wait???
if recv returns -1 errno may be set to 'EAGAIN' which means that there wasn't anything there yet so try again - maybe your getting that and just don't know it.

If you're getting -1 and errno == EAGAIN have your program sleep a little and try recv again.
Nov 15 '07 #10
weaknessforcats
9,208 Expert Mod 8TB
Again, I say, have you called WSAGetLastError() to see what is causing the
-1 error ???
Nov 15 '07 #11

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

Similar topics

2
by: Dan | last post by:
I'm writing a simplistic telnet client in VB6 and I've run into a small snag. The program has a textbox to write in the string to be sent using ..SendData and has another textbox that displays...
6
by: Christian Drescher | last post by:
I try to build something like a web interface for one of my tools. I have got a problem: char sendBuf = "HTTP/1.1 200 OK\nContent-Type: text/html\n\n<HTML>\n<BODY>\nHallo\n</BODY>\n</HTML>\n"; ...
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
5
by: windandwaves | last post by:
Hi Folk I proudly send my emails using John Rhoton's code for sending them directly via winsock. I now want to take this system to the next level and start sending emails with HTML content. ...
2
by: Dudule | last post by:
Hello, No answer from "comp.lang.basic.visual.misc", so i try to post here...: Using WINSOCK to acces the Web, in Visual basic 6 application, most of the time it is working fine, but with some...
1
by: raj.rr7 | last post by:
Hi, I am creating a Http client application using winsock, evc++ 4.0 and K- Jam (WIndows Mobile 5) that will get data from Http server. I am using the following code. WSADATA wsaData;...
0
by: danishce | last post by:
Hello All: I am developing a client/server application using vb.net winsock programming. I am sending data to Server and at the same time receive the incoming data from the server. My application...
1
by: danishce | last post by:
I am developing a client/server application using vb.net winsock programming. I am sending data to Server and at the same time receive the incoming data from the server. Everything works fine but...
3
AaronL
by: AaronL | last post by:
Hello, I am currently working on a project that has me in sort of a bind. What I want to do is retrieve web pages from the internet, and strip them down to just text. I'll get using Regular...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.