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

Home Posts Topics Members FAQ

reading http message on a socket

Guys,
i'm trying to receive a http message: i open a socket, bind and listen ..
then accept (and it works so far); when i receive to read the data on
the socket with the sock_read function, everything gets frozen

Any help from a more experienced programmer would be so appreciated.
#define PROXY_PORT 8080
#define MAXLENGTH 30000
using namespace std;

int sock_read(int sockfd, char *buf, const size_t count);

int sock_write(int sockfd, char *buf, const size_t count);

int main ( )
{

int sock = socket(PF_INET, SOCK_STREAM, 0);

struct sockaddr_in s_addr;

memset(&s_addr, 0, sizeof(s_addr));

s_addr.sin_port = htons(PROXY_PORT);

s_addr.sin_family = AF_INET;

cout << "Bind: " << bind(sock, (struct sockaddr*)&s_addr, sizeof(s_addr)) << endl;

cout << "Listen: " << listen(sock, 5) << endl;

while (1) { // listening permanently

struct sockaddr_in peer;

memset(&peer, 0, sizeof(peer));

socklen_t slen = sizeof(peer);
int new_s = accept(sock, (struct sockaddr*)&peer, &slen); //accept connections
char buf[MAXLENGTH]
int size = sock_read(new_s,buf,sizeof(buf)); //read message
// ... more code

}

// here follows the sock_read function
int sock_read(int sockfd, char *buf, const size_t count) {
size_t bytes_read = 0;
int this_read;
while (bytes_read < count) {
do {
this_read = read(sockfd, buf, count-bytes_read);
} while (this_read < 0 && errno == EINTR);
if (this_read < 0) {
return this_read;
} else if (this_read == 0) {
return bytes_read;
}

bytes_read += this_read;
buf += this_read;
}
return bytes_read;

}
Feb 6 '07 #1
1 2148
kant wrote:
i'm trying to receive a http message: i open a socket, bind and
listen ..
then accept (and it works so far); when i receive to read the data on
the socket with the sock_read function, everything gets frozen

Any help from a more experienced programmer would be so appreciated.
[..]

Since reading sockets is not defined in the language itself or in
the standard library, you should consider asking in the newsgroup
dedicated to your platform.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 6 '07 #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: Chris P. | last post by:
I have a C# application that connects to Perl application on a UNIX server. I am able to connect and communicate both directions with the server, but there are several occasions when it appears...
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...
1
by: Etienne Desautels | last post by:
Hi, I'm working on project where I need to grab video from an Axis IP camera. This camera send a stream of a multipart message on HTTP. I write this code (at the bottom of the message) to read...
4
by: Patrick Altman | last post by:
I am attempting to use a HEAD request against Amazon S3 to check whether a file exists or not and if it does parse the md5 hash from the ETag in the response to verify the contents of the file so...
3
by: Willy Stevens | last post by:
Hello, In my application I have to read sometimes quite big chunk of binary data. I have a buffer which default size is 32000 bytes. But how could I read binary data that exceeds 32000 bytes?...
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: 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...
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: 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...
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 ...

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.