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

error reading from socket

I am trying to send an integer from Java Client to C++ server. I
figured out how to do the conversion. However, I have a problem reading
from the socket.
This is my code:

int DataInputStream::readInt()//reads one integer from the client
{
int32_t var1;
soc->recv((void*)&var1, 4);
var1 = ntohl(var1);
return var1;
}

I am assuming that I need a loop, but I cannot figure out which one. I
tried all cases that I could imagine, but none of them worked.
I MUST use recv function. Here is how it is defined:

int recv(void *buffer, int bufferLen)
throw(SocketException) {
int rtn;
if ((rtn = ::recv(sockDesc, (raw_type *) buffer, bufferLen, 0)) < 0)
{
throw SocketException("Received failed (recv())", true);
}

return rtn;
}

Any help is appreciated.

Jul 22 '06 #1
1 2907
ms******@gmail.com wrote:
I am trying to send an integer from Java Client to C++ server. I
figured out how to do the conversion. However, I have a problem reading
from the socket.
What is your problem and where are your tests?
This is my code:

int DataInputStream::readInt()//reads one integer from the client
{
int32_t var1;
soc->recv((void*)&var1, 4);
var1 = ntohl(var1);
return var1;
}

I am assuming that I need a loop, but I cannot figure out which one. I
tried all cases that I could imagine, but none of them worked.
I MUST use recv function. Here is how it is defined:
A loop for what?
int recv(void *buffer, int bufferLen)
throw(SocketException) {
Exception specifications (other than throw()) tend to be more of
hindrance than a help. Consider what happens if another exception gets
throw.
int rtn;
if ((rtn = ::recv(sockDesc, (raw_type *) buffer, bufferLen, 0)) < 0)
{
throw SocketException("Received failed (recv())", true);
}

return rtn;
}

Any help is appreciated.

--
Ian Collins.
Jul 22 '06 #2

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

Similar topics

9
by: javastudent | last post by:
Hi, I am implementing a server that reads for socket connections at a port, and processes the socket on a separate thread. We do not control the client implementation. Here is the scenario. ...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
2
by: Rookie | last post by:
Hi, I was writing a simple program using sockets. The program is supposed to be a TCP server that receives a string sent by the client. For this purpose I defined a char array called readString...
6
by: Jason Chu | last post by:
situation: I'm uploading file to my application using a java applet sending the request (the file) through socket to my asp.net page. On my asp.net page, I've override the httpmodule to take in...
7
by: Nuno Magalhaes | last post by:
I've got a problem which relates to reading HTTP data. I've got the socket connected to a web site and then I send "GET / HTTP/1.1\n\n" and the page is received after a while but not all of the...
5
by: Dave A | last post by:
I have an application that does lots of socket communications all asynchronously via the TcpClient class. The code has been working 99.9999% of the time (yeah one of those bugs) but occasionally...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
0
by: Orbit | last post by:
Hi, I hope someone could help me. I have a simple web service that I developed on my laptop that resides within a large web application. It queries Northwind & presents the data in a grid in the...
3
by: nvr | last post by:
Hi all I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error ./Clientsend.c: line 11: syntax error near unexpected token `('...
10
by: puzzlecracker | last post by:
Say I want to arrange bytes in the internal buffer in a certain way. I receive those bytes in the socket. One solution is to read in socket in pieces: byte buffer = new byte; int index = 0;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.