All Questions
611
questions
13
votes
2
answers
9k
views
Unix sockets slower than tcp when connected to redis
I'm developing high performance web server that should handle ~2k simultaneous connections and 40k QPS, achieving resp time < 7ms.
What it does is querying Redis server (running on the same host) ...
10
votes
2
answers
13k
views
Does reading from a socket wait or get EOF?
I'm implementing a simple connection between a client and a server in C.
In client side, I'm in a loop, reading from a file; every time BUFFER_SIZE bytes and sending it to the server side (didn't ...
9
votes
2
answers
1k
views
C TCP sockets, echo server with file sending, hangs up after sending a file
I wanted to write a simple TCP echo server application. I managed to do the echo part, but have some problems with sending files between client and server. The idea is simple: despite sending ordinary ...
9
votes
3
answers
12k
views
Can a C socket recv 0 bytes without the client shutting the connection?
I've implemented a web server in C. It calls recv() on a connected, blocking socket to receive an incoming HTTP request. The Linux man pages state the following about recv() on a blocking socket:
...
9
votes
2
answers
4k
views
How to make OpenSSL C server only support TLS 1.3?
We are having a Linux C program making use of OpenSSL APIs, acting as a TLS server. It currently has code as:
context = SSL_CTX_new(TLS_method());
Which the OpenSSL v1.1.1 manual page says will ...
8
votes
2
answers
39k
views
How can I use sys/socket.h on Windows?
I made a server with C using socket on a Linux machine and it's working fine but when I tried to run it on windows machine using visual studio, I'm getting an error:
fatal error C1083: Cannot open ...
7
votes
1
answer
628
views
Implementing a 9p server
I am looking to develop a C implementation of a 9p file server on a Linux machine. There isn't enough documentation in the internet about 9p and I am not very experienced with implementing servers. My ...
6
votes
4
answers
7k
views
How does the accept() function work?
I have a question about the accept() function in C.
When a server receive a connection, the accept() function creates a new socket to communicate with the client, and then let the "old socket" ...
6
votes
2
answers
13k
views
How recv() function works when looping?
I read in MSDN about the send() and recv() function, and there is one thing that I'm not sure I understand.
If I send a buffer of size 256 for example, and receive first 5 bytes, so the next time I ...
5
votes
3
answers
15k
views
Client Server multiple connections in C
I am trying to reason about how a simple server implemented in C with sockets can handle concurrent clients. Let's say a simple server waits for a client to connect and then read a message sent from ...
5
votes
3
answers
640
views
How to cancel a function call if it takes too long to respond in C?
Is there a way to call a function, and then cancel or skip over the call if it takes too long to respond?
I'm simulating an ftp connection, and I'm receiving a response from a server using this ...
5
votes
1
answer
3k
views
What is the proper way to handle multiple clients connections on linux server
Hi I am writing server on linux in C language using TCP.
The server has to handle multiple connections (up to 5000 approximately). 5000 is max, but average should be about 500 - 1000.
I would like to ...
5
votes
1
answer
6k
views
Sending images over http to browser in C
A am new to C and I am trying to implement a web server in C. I can successfully send .txt and .html files to the browser. However, I can't send any images, although I have correct content-type header ...
4
votes
2
answers
743
views
What happens to an incoming connection trying to connect to a socket already processing a request?
I can accept() incoming connections while I listen() on my socket, but once I have accept()ed a connection and am processing the request, what happens to an incoming connection request trying to ...
4
votes
1
answer
6k
views
Polling TCP connections in C
I'm working on a school task where i have to make a server that gets TCP connections. Those connections then pass data. I use poll() to see if there is a new connection request or if there is incoming ...
3
votes
2
answers
7k
views
Problems With Websocket Server in C
I need to use NGINX as a WebSocket Proxy, and I've been able to run this tutorial without any problem. In this case, a simple WebSocket application is done using ws and Node.js. However, I need to ...
3
votes
3
answers
11k
views
Socket in C: Proper way to close socket
I often see sample codes for a server program using socket.
(For simplicity, here I don't check return values of functions such as socket() or bind() etc.)
int sockfd = 0, newsockfd = 0;
struct ...
3
votes
1
answer
336
views
Sending a string from C client to Java server
I'm trying to send a string from my c client to a Java server, after which the server sends a text file to the client.
This is the part of client code that sends the string.
int n = write(sock_fd,"...
3
votes
1
answer
5k
views
Curl doesn't send entire form-data in HTTP POST request
Edit:
Problem: 2 and Problem: 3 solved by following @melpomene comment i.e., by using number of bytes read to print the buffer.
But still struck on Problem: 1.
I have written a TCP server-client ...
3
votes
2
answers
6k
views
Upload HTML form data file to server using CGI in C?
I have a HTML form put in a CGI file in C with fprintf statements like this:
<form action="cgi-bin/upload.cgi" method="post" enctype="multipart/form-data">
<p>Photo to Upload: <...
3
votes
3
answers
989
views
Make local HTTP server inaccessable from outside
I want to write a program with HTTP server functionality on my Linux machine so that it can interact with my browser for showing formatted output etc.
After some research I decided to go with ...
3
votes
1
answer
934
views
Reusing linux abstract namespace socket
I would like to reuse one abstract socket adress during one server session. I tried to close sockets and bind them again, but it isn't working.
server.c:
#include <stdio.h>
#include <...
3
votes
1
answer
2k
views
Not able to catch a SIGINT signal while using pthreads
I have made a chat server which uses multi-threading for dealing with multiple clients. I have a while loop which runs infinitely and waits for new clients. I want to come out of it after I press ctrl+...
3
votes
1
answer
6k
views
(C) Using mutex in multithreaded client and server
I need help getting mutex to work the way I want. I am making a simple bank system with a server and multiple clients.
The server has two threads. One thread listens for connections. The second ...
3
votes
2
answers
561
views
Can only connect to Server once with Client in c
I'm writing in C and creating a Server that receives connections from multiple different Clients one at a time. However, after the first connection closes, the server can't be connected to again.
...
3
votes
3
answers
2k
views
Allow opening a file with open() only in one process, in c unix programming
I'm creating an application client/server. Users registered are located in their specific file. I need that only one process of my client can login with that specific username. So I think that the ...
3
votes
2
answers
147
views
I/O communication read and writing from client to server program
So I am playing around with the idea of ports and client/server communication.
I have a server.c program that can open a port, open a listening descriptor, and upon receiving a connection, fork a ...
2
votes
3
answers
7k
views
C: Using Select to monitor two sockets
I am writing a server that connects to multiple clients. At the moment, I am using accept on a SOCK_STREAM socket to connect new clients. I want to be able to accept queries from clients that send a ...
2
votes
2
answers
291
views
TCP sockets, send files, client server, server doest save a whole file, C language
I wrote a simple protocol in which Im able to exchange files / text messages between client and server. If the client send a text to server, server should simply echo it back. On the other hand, when ...
2
votes
2
answers
4k
views
Socket Programming - Multiple connections: Forking or FD_SET?
I'm trying to understand the different practices when it comes to socket programming and handling multiple connections.
In particular when a server needs to serve multiple clients.
I have looked at ...
2
votes
1
answer
917
views
Simple TCP server can't output to web browser
I wrote a simple TCP client and server program in C language.
It works fine among them but I have a doubt.
What if I wanted to access the TCP server from the web server?
I got the headers from web ...
2
votes
2
answers
4k
views
Server program gets stuck at accept function
I am working on a server application in C using Pthreads(Linux).Everything works fine, clients can connect with the server and transfer data. The problem being faced is that my software keeps stuck ...
2
votes
1
answer
13k
views
Asynchronous C client for a multiclient C server
I have a client which is working fine, but whenever I run a new client, sometimes I don't receive the sent message on the other client already running, while using telnet it works flawlessly, the ...
2
votes
1
answer
15k
views
How to download a file from a URL in C, as a browser would?
I want to download a file from a URL, this one : http://download.finance.yahoo/d/quotes.csv?s=YHOO+GOOG+MSFT&f=sl1d1t1c1hgvbap2
When i go on my browser and input this URL in my browser, the file ...
2
votes
1
answer
6k
views
poll() waits indefinitely although timeout is specified
I'm writing a C client-server program, in which the client has to receive a large amount of data from the server. Since I want my client not to wait indefinitely on a recv() if something goes wrong ...
2
votes
2
answers
857
views
c- HTTP server on sockets doesn't display image correct
My task is to implement a simple HTTP server. I try to open a site that I download via HTTP. My server displays html, css and js files properly, but images(png, jpg) don't get displayed. I logged ...
2
votes
2
answers
1k
views
Slow accept() in socket server in C
I have the following code for my education socket server in C.
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types....
2
votes
2
answers
960
views
C Socket Programming write/read dirty memory
I wrote two custom function for write and read on my C program that my university teacher suggested:
ssize_t FullRead(int fd, void *buff, size_t count) {
size_t nleft;
ssize_t nread;
...
2
votes
1
answer
50
views
"Bus error: 10" When attempting to read IPv4 address from C program arguments
I'm making a TCP server and client, and as part of the server program it needs to take an IPv4 address and port number as arguments at the function call.
#include <stdio.h>
#include <stdlib.h&...
2
votes
1
answer
2k
views
IPC : Node JS server communication with simple C code
I have a C code, that within a infinite loop waits for an input and produces an output.
#include<stdio.h>
void flush() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
...
2
votes
1
answer
3k
views
socket: listen with backlog and accept
listen(sock, backlog):
In my opinion, the parameter backlog limits the number of connection. Here is my test code:
// server
// initialize the sockaddr of server
server.sin_family = AF_INET;
server....
2
votes
2
answers
71
views
What's difference, passing directly sizeof() on function and a previous declared and initialized variable?
For example, I'd like to know if there is any significant difference or good/bad practice
Doing this way:
unsigned int length_addr;
length_addr = sizeof(cli_addr);
nbytes = recvfrom(sockfd, ...
2
votes
1
answer
3k
views
C Sockets Client/Server pthreads server broadcast
We were given this code, and was supposed to modify it so that whenever a client connects to a server and sends a message the server should reply I hear you dude. That is working for one and multiple ...
2
votes
2
answers
13k
views
C - Creating endless socket connection between server and client (Linux)
I have a simple socket program created in C (using Ubuntu), the connection works fine, server compiles and client provides the IP and port number.
But when the connection is established, the client ...
2
votes
1
answer
1k
views
Server binding results in error "Cannot assign requested address"?
I would like to create a server on localhost, using IPv6 mapped IPv4 address of the local host, but I get errno 99. I am not sure what am I doing wrong here:
#define IPv6_MAPPED_IPv4_LOCAL_ADDRESS "::...
2
votes
1
answer
72
views
How come I can print out each character separately but not as a whole?
This is one part of a server implementation where I'm going through the request line header and giving output accordingly. This might be a basic question. How come I can print out each character ...
2
votes
2
answers
124
views
detecting when a client-side application shuts down the connection inorderly
I am developing a 9p server, it is pretty much like an nfs server. Subsequent mounting and unmounting causes no socket descriptor file leakage because I am able to close the socket. However, in the ...
2
votes
1
answer
2k
views
Correct way to write/read integers in C socket programming
I need to pass an integer from a TCP C server with the write() function and receive it in a client with the read() function.
In my server, Let's say
int check = 0
How can I send it with a write() ...
2
votes
2
answers
9k
views
Getting client IP address and port?
I'm writing a file sharing program and the jist of it is that there is one main server which all clients connect to. However, the clients are the machines hosting the files so when one client requests ...
2
votes
1
answer
369
views
epoll server with EPOLLET. When should I mark a socket with EPOLLOUT?
So been trying to make an asynchronous server with epoll (edge-triggered). Everything seems to work fine unless I send large files (30-33 MB) over the socket, which ofcourse gives EAGAIN with send ...