Results 1 to 7 of 7
Hi, I need to make a daemon which listens to port 81 for messages like localhost/message?command=move&dir=left
So far I made a daemon which serves as a simple stream server: I ...
- 12-07-2009 #1Just Joined!
- Join Date
- Dec 2009
- Posts
- 3
[SOLVED] Handle query strings using socket programming
Hi, I need to make a daemon which listens to port 81 for messages like localhost/message?command=move&dir=left
So far I made a daemon which serves as a simple stream server: I set up a socket to listen to a non-reserved port (like 9999), but I don't know how to read the query strings.
Linux distro: Kubuntu 9.04
Language: C
- 12-07-2009 #2
man recv
File: *manpages*, Node: recv, Up: (dir)
RECV(2) Linux Programmer's Manual RECV(2)
NAME
recv, recvfrom, recvmsg - receive a message from a socket
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen);
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
for complete details open a terminal and type info revc or man recvMake mine Arch Linux
- 12-08-2009 #3Just Joined!
- Join Date
- Jun 2009
- Posts
- 5
Are you having trouble with knowing where the query strings get passed to you or how to read data from the socket?
- 12-09-2009 #4Just Joined!
- Join Date
- Dec 2009
- Posts
- 3
- 12-09-2009 #5Just Joined!
- Join Date
- Jun 2009
- Posts
- 5
They get passed by the browser in the Http Request:
This is sort of a minimal HTTP Request:
<start HTTP Request>
GET [pathToPage]?[queryString] HTTP/1.1
Host: [yourhost]
[other headers here...]
<end HTTP Request>
Notice that the header region ends with two newlines.
Hope that helps.
- 12-09-2009 #6Just Joined!
- Join Date
- Jun 2009
- Posts
- 5
Also, you might try getting a packet sniffer just to be able to see what "real" requests and responses look like. (Wireshark seems to be a good one)
- 12-09-2009 #7Just Joined!
- Join Date
- Dec 2009
- Posts
- 3
I finally managed to get the query string. It worked with recv. I wasn't reading the buffer correctly because I didn't know the format. Thank you for your help.



