C :: Linux Socket Multiple Connections But With Different Time Rate
Feb 6, 2015
i want to write a server and a client as below:
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.
View 4 Replies
ADVERTISEMENT
Jan 29, 2014
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?
View 1 Replies
View Related
Nov 26, 2013
I created a .h file for mysql connections. In my example file, I created an array of my class and made connection with the database for each subscript of the class object one by one. Then I checked if the connection in the previous subscripts are active or not, I found all the previous connection are disconnected.
I want to establish multiple connection with database at a time.
View 1 Replies
View Related
May 18, 2012
following code because i want to handle multiple connection and want to implement in my project
Code:
int newsockfd, pid;
socklen_t clilen;
struct sockaddr_in cli_addr;
[Code]...
My Questions
1. What these lines is doing
Code:
newsockfd = accept(m_sockfd, (struct sockaddr*) &cli_addr, &clilen);
Code:
close(m_sockfd);
Code:
close(newsockfd);
2. And why there is no create(), connect(), read(), write() methods for client
View 1 Replies
View Related
Apr 4, 2012
I am trying to code a C program for sending a struct over TCP Socket in Linux! The code is as follows:
/*
** sravan_server.c - a stream socket (TCP) server Program
*/
#include <stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>
#include<string.h>
[Code] ....
View 4 Replies
View Related
Oct 31, 2013
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".
View 3 Replies
View Related
Mar 16, 2014
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;
[Code] ....
View 1 Replies
View Related
Sep 3, 2013
I want to put my socket programming example of how it can support multiple ports. I want to make the process more requests from distributing particles to create non-blocking structure
ports support ports defined variable.
Code:
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "errno.h"
#include "string.h"
#include "sys/socket.h"
[Code] .....
View 2 Replies
View Related
Nov 29, 2010
I have a tcp client - server implementation running in the same program, on different background worker threads. There will be instances of this program on multiple computers so they can send and receive files between each other. I can send files sequentially between computers using network stream, but how would I send multiple files at the same time from computer A to B.
Sending multiple files over one connection ( socket ) is fine, but having multiple network streams sending data to a client, the client doesn't know which chunk of data is apart of which file ?
View 3 Replies
View Related
Sep 18, 2013
I'm doing work on chat messenger and facing difficulty to run multiple threads at the same time. Here is the sample code.
void menu();
void groupChat();
void personalChat();
int main() {
sf::Thread thread(&menu());
thread.launch();
[Code] ....
In my program, after menu when he selects a choice, next display of menu wait the termination of the selected thread.
while i want to show menu right after when a menu is selected.
View 2 Replies
View Related
May 9, 2012
I can't run my server immediately after closing it, it leaves some connection(zombies) leave open after the server is terminated. and i have to wait for some time to run the server again but immediately can't start the server
Here is my code
#include "NetManager.h"
NetManager::NetManager(){
}
NetManager::~NetManager() {
[Code] ....
View 10 Replies
View Related
Oct 16, 2012
I made a C++ Wrapper on top of ODBC.
I got a Connection, and a Statement class.
The Connection class holds the Database Connection ODBC Handle.
The Statement class holds the Statement Handle, there can be multiple per Connection. It is made and destroyed each time a query must be done on the DB.
Now I'm just wondering.
I have a multithreaded application.
Is keeping one Connection for one DB enough for the whole application? Where the different threads will make Statements based on that one Connection.Or is it better to keep a Connection per thread?
View 3 Replies
View Related
Jun 7, 2013
I am making this program for a class and it works fine except for the daily interest rate for the checking account is off. The daily interest for the savings computes perfectly. The monthly interest rate for savings is 6% and for checking 3%.
Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <iostream>
#include <string>
using namespace std;
const int DAYS_PER_MONTH = 30;
[Code] ....
View 1 Replies
View Related
Apr 11, 2012
I use ffmpeg codes in my C++ app and would like to control the bit_rate parameter for VIDEO there. I tried to change its value in work (via ost->st->codec->bit_rate = 150000), but ffmpeg did not wish to change it.
I tried to make re-init of the codec:
Code:
....
ost->st->codec->bit_rate = 150000;
AVCodecContext* newContext = avcodec_alloc_context3(ost->enc);
avcodec_copy_context(newContext, ost->st->codec);
avcodec_close(ost->st->codec);
av_free(ost->st->codec);
ost->st->codec = newContext;
avcodec_open2(ost->st->codec, ost->enc, &ost->opts);
the program hanged after that codes.
View 2 Replies
View Related
Aug 5, 2013
The question involves me writing a program using a overloaded function to calculate the Weekly rate of employees but they get paid hourly and weekly. I get this error but do not know why,
#include <iostream>
using namespace std;
int calcWeeklyPay(int paidWeekly, int annualSalaryWeekly)
//Returns the Weekly salary of weekly paid Employees
int calcWeeklyPay(int paidHourly, int annualSalaryHourly)
//Returns the Weekly salary of Hourly paid Employees
[Code]...
View 3 Replies
View Related
Apr 7, 2014
I have a problem requiring me to :
enter loan amount:
Enter interest rate:
Enter length of loan (years)
It wants me to input the minimum amount for the loan, and the minimum interest rate. and then output a table that has 5 loan amounts across the top in $10000 increments and 4 interest rates along the side in .25% increments.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
double loan, interest, length, payment,ti;
//Enter loan price
[Code] .....
View 1 Replies
View Related
Oct 5, 2014
Write a payroll program that prompts for the number of hours an employee worked, as well as the employee’s pay rate. If the employee worked for 40 hours or less, the gross pay is calculated by multiplying the number of hours worked by the pay rate. If the number of hours worked by the employee exceeds 40 hours, the employee should receive regular pay for the first 40 hours, and receive time-and-a-half pay for the hours in excess of 40. Display the calculated gross pay on the screen.
Continue to prompt for similar data for more employees and have the gross pay of each employee displayed, until there is no more employee data to process. Then display “Good Bye”.
Your solution must be separated into three source files (Interface, Implementation, and Test)
View 3 Replies
View Related
May 14, 2015
I'm currently working on a program that calculates shipping charges. However I'm stuck, whenever I compile the program the total amount at the end always comes up as my flat rate variable and not the total calculated number.
Code:
#include <iostream>
#include <iomanip>
#define FLAT_FEE 5
using namespace std;
int main() {
double num, pound, ship;
ship = FLAT_FEE;
[Code] ....
View 6 Replies
View Related
Oct 8, 2013
Write a program in C++ that calculates the amount to be paid to an employee based on the hours worked and rate per hour. A user will enter hours worked and rate per hour for an employee. Your program should have a function payCheck that calculates and returns the amount to be paid. The formula for calculating the salary amount is as follows: for the first 40 hours, the rate is the given rate (the rate that a user has entered); for hours over 40, the rate is 1.5 times the given rate.
I had write my own coding, but it keeps error. it is okay. But i still don't think i could share here? Still running... I will update my coding for you alls to check for any syntax or logic error. The problem is i need to calculate if the employee work for more than 40 hours which 1.5 times.
Code:
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
using namespace std;
int main(void) {
char *empname, *test, *final_output;
[Code] .....
View 7 Replies
View Related
Mar 10, 2015
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
[Code] ....
View 2 Replies
View Related
Apr 11, 2013
I have a code that I'd like to debugg it.
Question
1 - What is the correct command line to use the debugger ?
2 - Do I need to install additional software for the debugger ?
if yes what it's name?
I use ububtu 12.4compiling command: gcc abc.c -lpthread -o abc
View 3 Replies
View Related
Feb 22, 2015
This is what so far i did
Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#include <bsd/string.h>
int
main(void)
[Code] ....
How to do this Using the fork(), execvp() and waitpid() system calls, launches the requested program and waits until the program has finished.
View 3 Replies
View Related
Jul 6, 2014
I am an experience C programmer but never implement GUI.
I need to make a demo implementation that will be run on Linux and will implement GUI.
I searched the WEB and found lot of information, among is implementing the GUI in HTML and run the API through web browser.
How can I make such implementation in C?
View 2 Replies
View Related
Sep 22, 2014
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)
{
[Code]....
View 10 Replies
View Related
Aug 16, 2013
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.
View 14 Replies
View Related
Apr 24, 2013
I have this following piece of code:
int id = 5;
const char *ptrId;
ptrId = ( int_to_str(id) ).getPtr(); // Works in Solaris well
But the above code prints some junk values when I run the same on Linux machine. But the following works well on Linux:
String temp = int_to_str(id);
ptrId = temp.getPtr();
The prototype of getPtr() is:
const char* String::getPtr() const
View 2 Replies
View Related