That's because client_address is casted into (struct sockaddr*). I get the same issue no matter if I put
socklen_t client_address_len = sizeof(struct sockaddr);
client_sock =...
Type: Posts; User: karas
That's because client_address is casted into (struct sockaddr*). I get the same issue no matter if I put
socklen_t client_address_len = sizeof(struct sockaddr);
client_sock =...
Hi,
I am trying to make an echo server under Windows similar as one under Linux.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
#include <ws2tcpip.h>
fork() makes a copy of the calling process. Here is an example of the server which accepts clients and process them in a separate process (created by forking).
/*
server_forked.c...
You can fork process for each accepted client, you can use threads for each client or you can use multiplexing. For the start, you should read tutorial at Beej's Guide to Network Programming. There,...
I have a dummy multiplexed server (which echoes requests) working under Linux just fine. I'm testing it on FreeBSD 8.0 and I have a strange behavior. When I use
int client_fd = accept(server_fd,...
Beej's Guide to Network Programming is good for the start.
Poco (POCO C++ Libraries > Info > About) also has socket classes and it is under Boost license. Documentation and examples are quite good.
Thanks, that's what I needed to know.
Ok, and why SIGPIPE is raised with Unix sockets and not with Internet sockets? When I use Internet sockets, there's no need for server to catch this signal, only check when recv() returns 0.
Any suggestion how to put timeout into server?
Hm, that could be solution, but question still remains: why Internet server knows that client interrupted and does not have broken pipe, but Unix server cannot figure it out and receives broken pipe?...
Hi,
I'm experimenting with Unix sockets, and I have a problem when client interrupts connection (with Ctrl-C for example).
Server accepts connections and each client is treated in forked process...
Thanks, that was the problem. Here's the code which works:
#include <arpa/inet.h>
#include <netdb.h>
int main()
{
struct sockaddr_in sa;
sa.sin_family = AF_INET;
Hi,
as I understand, getnameinfo() is used for reverse lookup i.e. to get hostname from the IP address. So, what's wrong with the following code
#include <arpa/inet.h>
#include <netdb.h>
...
It works, thanks.
Hi,
the following code
int main()
{
struct servent* se = getservbyname("telnet", "tcp");
printf("%d\n", se->s_port);
}
Two last commands compile files into executables, if you noticed.
That's because you're using spaces instead of tabs in lines where command has to be executed. For example
$(CC) $(CFLAGS) $(OBJECTS) -o $(PROGNAME)
must be indented with tab not with...
I compiled successfully from command line with
gcc -c *.c
gcc myshell.c
gcc tablegen.c
g++ client.cpp -o client
g++ server.cpp -o server -lpthread
compiles client and server. Beside standard library you need only thread library which is probably installed during Linux installation.
Thanks.
Hi,
I made some tests with passing sockets to the threads and there's a problem with the following code.
First, here's the client who's connecting to the server. It sends 1000 times a number to the...
Yes. The first one is dynamic allocating (so called heap memory) and requires deleting after use. Otherwise it will produce a memory leek. The second one is freed automatically and the reserved...
Found: xmlReadDoc() should be used instead of xmlParseDoc() and the option for suppressing can be specified as last argument.
If some error occurs during parsing the XML document (stored in file or RAM), the library function that caused error (xmlParseFile() or xmlParseDoc()) prints the errors on the stdout. Is there a way...