I'm attempting to write a little UDP socket library in c++ on linux so a user can just create a new instance of a UDPSocket class, specify destination ip and port, and just connect. Then the user should be able to call send() or receive() in any order they want.. and here I encounter a little problem..
Most of the tutorials for udp socket sending out there include a bind() call when you create your "server" that is supposed to receive data, but the code that send data does not need one. Because I also want my library to support unicast/broadcast/multicast, I have read that I need to set the socket option SO_REUSEADDR on my sockets (since multiple sockets will need to be connected to same destination IP/port for broadcast/multicast)
My question is.. do I need to create 2 socket handles per "UDPSocke in order to make this work? One for sending and one for receiving data? In my code when I try to work with only 1 socket, it is only able to receive stuff from itself on unicast.. Or should I just remove the SO_REUSEADDR when in unicast mode, then try to bind with both sockets, accept that the bind will only work on the 1st socket, and take it from there?
The server(and not the clients) will connect to the clients and just send a message. The idea is to be able to connect at each client a different time.
e.g every 10mins connect at client 1 every 2mins connect at client 2 every 1hour connect at client 3 and so on...
So how to implement this ? Should i create a new child process for each connection and what about the timing ? A pseudo code also will work.
I am writing on C simple socket programs in Linux. I wrote client and server C programs. My client program is Code: #include<sys/socket.h>//for socket(), connect(), sendto() and recvform()
#include<sys/types.h> #include<netinet/in.h> #include<netdb.h> #include<stdio.h>// for printf() and fprintf()
[Code]....
I am just testing whether can connect or not. I run server program first and client later. But when I run client, it showed that "Address family not supported by protocol".
This is my sample socket tcp ip program , problem here is when i give working ip address and port number, it is showing default ip address as 127.0.0.1 and it is Waiting on (1978=port number) i.e., "connection on %d...", SERVER_PORT.
void socket_server_demo(void){ int iserver_socket = -1; int iclient_socket = -1; unsigned char bTemp[1024]; unsigned int iTemp = 0;
I've been reading about libraries; How to make them, how to use them, the different types of libraries, etc..
When using a shared library, does the program require that library to be installed on the computer after the program has been compiled into an .exe?
Ie.. if somebody downloaded a "Helloworld.exe" that I had compiled on my computer using a shared library (that wasn't part of a standard operating system), would they also need that shared library on their computer for the program to run without errors?
and for Static Libraries, when I compile a program using a static library, does it include in the final binary only the functions of the library that are actually used, or does the compiler add in the entire library?
I want to use two separate files in 1 program, but cannot get it to work. I don't know if it's my files or the compiling thats wrong. I have never used 2 files in my programs so far. Only used #include <stdio.h>.
Here are my files: extern_static.c Code: extern int i; int main(void) {
I have a c file which can be compiled in Linux via GCC , but when I compile it in NetBeans via Cygwin or MinGW , it doesn't work and keeps throwing a segmentation fault.
I want to open an application A from another application B. By opening it, I don't want to open it within B. I found many ways to call an application from within another. However, what I want to do is open the other one(A) simultaneously. How can I achieve this? fork() and exec() seem to open A within B. I am developing a code for Linux and Mac.
I'm trying to implement this on ubuntu, to compile and run only under ubuntu.
I found 100s of other attempts at answering the general question of arrow key press in c++. Nothing solid.
Some recommend using the Readline for the functionality I am trying to implement, but I need to stay clear of GNU licences if I can for this project. And some tips only work on projects for windows machines... for example the conio library.
For linux there may be the option of using the ncurses library which I will take a look at, but I am stubborn and want to implement this myself. It should be an easy straight forward thing to do, which is why I am a bit frustrated at the moment.
So! This works... 80% of the problem is solved. If you compile this, g++ under linux, ubuntu in my case, and run. Each keystroke reveals the correct key numbers.
q=113 w=119
when I click on the up key I get,
up = 279165
I thought, I can use this number is a if(int == '279165') to detect the up key.
I was not so lucky... this int is not behaving like an int!
So I modified the code to see it I could carry out an int operation on this number.
Compiling and running this, and pressing the UP key gives the following number.
100027100091100065
Some some sort of array, something like, [27][91][65].
I tried all ways to access these individual numbers, actually the third one for comparison purposes, but no luck.
For completeness sake I list the other arrows.
UP = [27][91][65] DOWN = [27][91][66] LEFT = [27][91][68] RIGHT = [27][91][67]
A little further digging shows that these numbers are derived from the representation of a "multi-char" constant, the data type given when pressing special characters...
Now here is the main problem I have, I can find ANY decent documentation on how to handle and play with "multi-char" .
I am trying to test my client-server socket program wherein the client connects to the server,client sends a message, server receives it and echo back to the client.So far, in the program server receives the message from the client, prints it BUT when it tries to send the message back to the client it shows an error.
sendto(): Invalid argument.I am new to socket programming.
Code:
//Server #include<stdio.h> //printf #include<string.h> //memset #include<stdlib.h> //exit(0) #include<netinet/in.h> #include<sys/socket.h> #define BUFLEN 512 //Max length of buffer #define PORT 10003 //The port on which to listen for incoming data }
I am trying to detect keys pressed on a keyboard and mouse on both, Windows and Linux but I am unsure what would be the best practice way to do so. Will I have to detect the keys for each platform individually? Would you make use of an event listener? What's the best way to detect the input-devices?
I'm writing a server/client application in C++, one linux and one windows. The generic communication method is to use the boost::serialization package, but I'll also use a header to distinguish the type of the serialized string.
Here is the struct that the two programs communicate with
When one side wants to pass an object to another side, it uses typeid(T).name() for the field type_name. The receiving side receives SerializeString and checks its type_name against various acceptable structs as follows:
if (ss.type_name == typeid(XXX).name()) { // deserialize ss.serialized_string to XXX and do something with it } else if (ss.type_name == typeid(YYY).name()) { // deserialize ss.serialized_string to YYY and do something with it } else if (ss.type_name == typeid(ZZZ).name()) { // deserialize ss.serialized_string to ZZZ and do something with it } else { // etc... }
This worked fine when I was using Windows VS2013 on two different windows platform. However when I switch one to Linux there is a problem because their typeid(XXX).name() returns different things. So question here, is there a generic way to get some sort of unique names across platform / compiler? Or is my method reasonable at all?