Categories
Linux Mastering Development Ubuntu

Chat in ubuntu terminal between two computers via network

I got a task to do for my studies. We have to make a chatroom between two ubuntu systems on virtual machines. Systems are on different computers. We have to connect via Network. Do we have to use the same Network? I already did it between two terminals on the same computer, but I do […]

Categories
Linux Mastering Development

LIFNAMSIZ undeclared, even though net/if.h included

I am trying to compile the following source on CentOS (taken from here): #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <net/if.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/poll.h> int recvFd(int cltsock, int *recvsock, char *iname) { struct msghdr msg = {}; struct cmsghdr *cmsg; char buf[CMSG_SPACE(sizeof(int) * 1)] […]

Categories
Mastering Development

Reading From One Child Process Blocks Other Children

As you can see from the code I shared below, I am trying to implement 1 central server and n children. First I create all n children by forking from the server. Also, before forking I create bidirectional pipes using Pipe. Having forked and created n children, I want to read characters from child codes. […]

Categories
Mastering Development

Segment Violation socket in C

I’m developing a socket which is a tcp client and tcp server, but I’m getting segment violation, don’t know why, as I have understood this could be an error while assigning memory. Client code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> struct Datos{ char ciudad[30]; char […]

Categories
Development

Why does read() block indefinitely when reading a buffer

I’m new to socket programming and wanted to try something simple. This program can manipulate settings on my tv. All messages are 24 bytes. There may be one or more messages returned. I cannot figure out a good solution to get all of the messages without read() blocking on me. What is below would be […]

Categories
Development

p2p windows sockets in c++

I would like to create a process that tries to access an other process by winsock2.h in C++ an if he can’t, starts to listen for another process (the same program). The aim is to have a kind of p2p network (for the moment doing nothing). I would like then to separate both parts in […]

Categories
Development

Sending 2D array from Client to Server via TCP/IP preserving its shape

how can I send a 2D array from a Server to Client(s) as if they played chess? This is my server.c file: // Global variable int serverSocket = 0, clientSocket = 0; ClientList *top, *lastAdded; #define RIGHE 5 #define COLONNE 5 typedef struct ClientNode { int data; struct ClientNode* prev; struct ClientNode* next; char ip[16]; […]

Categories
Development

Read data from fd which was received from fusermount failed

I want to test fuse and copy some code from libfuse like this: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/wait.h> #include <unistd.h> #define xlog(_fmt_, …) \ printf(“\033[0;33m[%s:%s:%d]\033[0m ” _fmt_ “\n”, __FILE__, __func__, \ __LINE__, ##__VA_ARGS__) static int receive_fd(int fd) { struct msghdr msg; struct iovec iov; char buf[1]; int rv; […]

Categories
Development

Server socket does not receive the message the first time. Why does this happen?

I have hit a weird situation. I am creating a simple echo client-server. The client is able to send message to the server. The accept call succeeds in the server but for some reason, it does not detect the client message the first time. But when the client sends the message the second time, the […]

Categories
Development

Continuously sending data from server to receiver using c++

I am coding in C++ using winsock api. I am making a multi- client server chat. The problem that I am encountering in my code is that my server is able to send the message to the client only once. But I want this to happen multiple times. I cannot put accept() function out of […]