C :: UDP Application Simulate Packet Loss

Aug 12, 2014

have udp server-client application written in C. On the client side packet loss is detected using recvfrom function and sequence numbers of packets. How can I now simulate dropped packet's on the client side, for example if server is sending 1000 packet I want to drop 20% of them? I want to do this in the code, not for example using ip tables or WANEM or something like that. And one more thing, I have few clients and I want that they can dropped different packets, not the same one.

Code:
while(1){
nbytes = recvfrom(socket, buffer, MAX_SIZE, 0, (struct sockaddr *) &srv_addr, &addrlen);
if (nbytes != -1) {
// packet is received

}else{
//packet is not received
}
}

View 2 Replies


ADVERTISEMENT

C++ :: Reading Bytes Without Bit Loss

Apr 13, 2013

I need to read repeatedly data from a MPEG2 file to the buffer of 188 bytes and analyse data bit by bit.

I have the problem with correct bytes reading from file. In my code listed below I have two methods for that.

First one is lossing this bytes which in hex_base mode have 0 at the begining, eg: 03, 0F, etc.

The second method based on read function which need to have buffer as a char (lenght > 1 byte). Because of that I receive different values from that from file in some cases.

How can I properly read such file?

Code:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <windows.h>
using namespace std;
int main() {
fstream plik_in;

[Code] .....

View 2 Replies View Related

C++ :: Quadratic Formula Loss Of Significance And Simplification

Feb 16, 2015

write codes that could solve a quadratic formula, and my codes are like this:

#include <bjarne/std_lib_facilities.h>
int main()
{
cout << "Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
";
cout << " a? ";
double a;
cin >> a;
cout << " b? ";

[code]....

Which runs perfectly, but I have 2 questions:

1. How to simplify these code? On the assignment sheet the professor wrote about using void solve_linear(double b, double c); and void solve_ quadratic (double a, double b, double c);which I currently dont understand how these works. He asked us to write a well-encapsulated (as short as possible) program.

2. These are for extra points: the precision problem of floating numbers: professor asked us to find a way to get the precise answer of it, like this: Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
a? 1
b? -20000
c? 1.5e-9
Trying to solve the quadratic equation 1*x*x + -20000*x + 1.5e-09 == 0
Using classical formula: Two roots, x = 20000 and x = 0
Using stable formula: Two roots, x = 20000 and x = 7.5e-14

My guess is that
A. Using code like if(x1*x2=a/c) to check if numbers were approximated.
B. Somehow determine the larger one in x1 and x2.
C. Somehow use that larger one to do something

View 2 Replies View Related

C++ :: Array Data Loss After Return From Function

Oct 2, 2013

I have an object that I use to store data. Two of its members are dynamic arrays. When passed (by reference) to a function used to fill the arrays with data, everything works fine. However, only the 0th index of the arrays remain populated after the function call.

parameters.cpp // class reference

#ifndef parameters_H
#define parameters_H
using namespace std;
class parameters {
public:
double k;
double c;
double a;
double vci;// Cut-in velocity

[Code] .....

View 19 Replies View Related

C :: Sending A Packet Over Sockets

Oct 30, 2013

I have a socket connection already set up, my thing is what would be the best way to send a packet through sockets? My teacher wants us to convert the packet to bits first before we send it. I think he wants something like this:

Code:
struct packet{

int header
int message
int flag

}clientpacket; m

My question is how do we covert this to bits, before sending it. One of my friends said we can create a char[] array the size of the struct as a buffer. will memcpy() change the struct to bits if I copy it to the buffer?

this is how is suppose to look in bits for the header field/column.

Field : header
Field size(bits): 8
data format: Unsigned int
value example: 1
Value in bits: 0000 0001

I am confused, I think I send a structure over the socket but I did not convert it to bits before I sent it .

View 13 Replies View Related

C :: How To Create Packet Data

Jan 8, 2014

How can header info 'foo' be combined with data in buffer 'buff' to pass to sendto function

Code:

/* Send a single RTP packet, converting the RTP header to network byte order. */
int sendrtp(int fd, struct sockaddr_in ........ockAddr, struct rtpheader *foo, void *data, int len)
{
char *buff = alloca(len+sizeof(struct rtpheader));
foo->b.sequence = htons(foo->b.sequence);
foo->timestamp = htonl(foo->timestamp);
foo->ssrc = htonl(foo->ssrc);
}

[code]....

View 2 Replies View Related

C :: Send Data Packet

Mar 6, 2015

how to send datapackets. When we send a data packet from device to another, say I have a "string". How Do I send it? Are data sent as a hex or binary number?If so do i first convert the "string" into hex or binary and then send it over the communication medium(say UART)??

I have two hex numbers to be sent using the UART, do i wrap it in some specific form and send it and retrieve it on the other side?Say if I have a data structure, in that case how do i send it? Sending data packets is very cruicial in an embedded system.

View 3 Replies View Related

C :: More Packet Received Than Threaded Sender Sent

Dec 15, 2014

Questions : I am running a client Server Program whose Sender and Receiver loop is given below .I have multi threaded Sender using OMP .As per My logic Receive should receive same amount of data send by Sender ,But its receiving more packet than Sender sent .I am not able to identify the Bug !!

Code:
/*
Running As Follow :
gcc UTGen.c -o Sender
gcc UTGen.c -o Receiver

./Receiver -m 0 -p 5000 -z 256 -P t

export OMP_NUM_THREADS=4
./Sender -m 1 -s localhost -p 5000 -z 256 -T 10 -P t
*/

[Code] .....

View 3 Replies View Related

C++ :: Building Multicast Packet - Memcpy Casting

Aug 19, 2014

I am just getting back in to C++ after 10 years not doing any, contributing to an open source project. I'm adding in some functionality and am hitting a road block.

I need to send a multicast packet out on the network that is structured in a certain way. I have the definition, and know what data is going in each byte. I can successfully send a message using multicast, I now just need to send the right message.

I have used a char array to hold the message, as each char represents 1 byte, and I can transmit the array.

I am having trouble putting all of the data in the right place though. If my source data is a string, then I seem to be able to convert it, but if it is a short or int, then I keep getting errors when compiling. Similarly, two of the lines, (version and type) i initially tried using char arrays with a length of one.

Should I be using memcpy or a different function, or even be doing this in a totally different way altogether? This is the code that I am using, along with the packet structure:

//Construct a Zone Query packet
// 4 bytes - Signature "Ohz " = 0x6f, 0x68, 0x7a, 0x20
// 1 bytes - Version = 1
// 1 bytes - Type (0 = Zone Query, 1 = Zone Uri)
// 2 bytes - Entire message length = 12 + zone length
// 4 bytes - Length in bytes of the zone ID
// n bytes - Zone ID to query

[Code] ....

The errors that I get are:

error: invalid conversion from ‘short int’ to ‘const void*’ [-fpermissive]
memcpy(buffer + 6, packetLength, sizeof(packetLength));
^
[Code] ....

View 9 Replies View Related

C/C++ :: Winsock Sending Packet Header With Data

Apr 16, 2015

This question is kind of a continuation of Winsock Sending X264 Nal Unit. I was finally able to solve that problem, turns out in the end I was missing a memcpy(). Now my current issue is, when I try to decode the received packets, I am shown a bunch of errors. I have attached a picture with my decoding errors. So since I am using a reliable multicast socket, which doesn't guarantee order of delivery. My initial thought is that I am getting packets out of order.

So my question is, how would I attach a packet header to my current data? Could I get away with sending the header separately? Similar to what I am doing with the nal length. If I do attach my header to the packet data, what is a good way to delimit the two?

Server:

#include <WinSock2.h>
#include <WS2tcpip.h>
#include "wsrm.h"
#include <Windows.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include "x264Encoder.h"

[Code] ....

My client is just reading packets into a vector, because decoding it right away was too slow. So I thought that might have been an issue, so I decided to read in 200 packets just for testing purposes.

Attached image(s)

View 6 Replies View Related

C :: How To Calculate Total Sum Of Delay Of Receiving Side Packet

Dec 17, 2014

I want to calculate the total some of delay pf receiving Side Packet . Code is as Follow ..

What is weird that even if i invoke a sleep of 2 sec ,than its show delay always zero. Delay will be in microsec ..Is there any problem with logic or anything else..

Code:

do
{#pragma omp parallel private(nthreads, tid) {
/* Obtain thread number */
tid = omp_get_thread_num();
if (tid == 0) {
nthreads = omp_get_num_threads();

[Code]...

View 2 Replies View Related

C :: HTTP Packet Generation And Send / Receive Via Socket

Dec 26, 2014

I have Build code for sending/receiving TCP Traffic over c Socket . Now I want t add HTTP Protocol to it .

After searching out on google ,one method I found which is by GET method to send a query to a server like google.com and request a page .

But ,Suppose I saved a HTML page in my directory how can I send HTTP packet via client/server in socket using this HTML page .

View 4 Replies View Related

C/C++ :: HTTP Packet Generation And Send / Receive Via Socket

Dec 27, 2014

I have code for sending/receiving TCP traffic over C socket. Now I want to add HTTP protocol to it. After searching the web, one method I found which is by GET method to send a query to a server like google.com and request a page.

But, suppose I saved a HTML page in my directory how can I send HTTP packet via client/server in socket using this HTML page.

Server side code:

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
listen(sockfd,5);
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,&clilen);
while (1)

[Code] .....

View 1 Replies View Related

Visual C++ :: Getting Port Number Of A Packet In Pcap File

Jan 19, 2014

I am programming in c++ with 'winpcap' . I read a .pcap file and after I want to get the source and destination of packets in that file. Here is a piece of my code:

Code:
////I define the sructures here
#pragma pack(1)
struct sniff_ethernet {
u_char ether_dhost[ETHER_ADDR_LEN]; /* Destination host address */
u_char ether_shost[ETHER_ADDR_LEN]; /* Source host address */
u_short ether_type; /* IP? ARP? RARP? etc */

[Code] ....

but the result is incorrect? where is the problem?

View 5 Replies View Related

Visual C++ :: Sending Packet Of Type Byte To Serial Port

Feb 26, 2013

I need to send a packet of type byte:

0x00, 0x01, 0x02, 0x11, 0x00, 0x00

to a device via the serial port and then I receive and store data coming from device like this:

0x01, 0x01, 0x01 , 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00.

Writing lines of code through which:

1) I create the array
2) the sending the array to serial port
3) I'll see what I'm sending
4) I get the data

I'm using Visual Studio 2010 and C + + or VC++ language.

View 14 Replies View Related

C# :: Server Application Using Tcp Protocol And Then Establish Connection With A Client Application

Nov 29, 2014

What happens if I make a server application using tcp protocol and then establish connection with a client application but the server crash and then the client send data. Will the data be lost or the system will continue trying to send it?

View 2 Replies View Related

C# :: How To Start Application And Automatically Pass Input To That Application

May 9, 2012

I want to create an application that starts an application and passes input to that application. I know how to start a process using the classes in System.Diagnostics, but I don't know how to pass data to the process.

For example, and this is just an example, I would like to be able to automatically start an application that requires a username and password and automatically enter the username and password. Of course, that might open the door to security vulnerabilities, but that's not the point of the exercise.

How to implement the functionality I described? Is there a general way to go about doing this or does it depend entirely on the idiosyncrasies of the application in question?

View 2 Replies View Related

C++ :: Simulate Random Walk In 2 Dimensions

Jan 6, 2015

I am writing a piece of code that simulates a random walk in 2 dimensions (an object chooses whether to move up, down, left or right randomly). I would like the program to run the simulation for many objects at the same time. The way i have written it means that for every object i add the code becomes about 40 lines longer. Any method that would simplify the code so that i could have many objects but not pages and pages of code.

#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>

using namespace std;
double dist(int a, int b);

[Code] .....

View 5 Replies View Related

C++ :: Program To Simulate Coin Toss

Nov 14, 2013

Write a program that simulates coin tossing. For each toss of the coin, the program should print Heads or Tails. Let the program toss the coin 100 times and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip that takes no arguments and returns 0 for tails and 1 for heads. [Note: If the program realistically simulates the coin tossing, then each side of the coin should appear approximately half the time.]

View 7 Replies View Related

C++ :: How To Simulate File Space Allocation

Mar 29, 2014

I want to write a c++ code that due the structure of file space allocation,Simulates file system with 2*n array. Each column represents a sector. The first row is for storing files And second row holds the address of the next sector (Number of columns). And With each click on keyboard Create a file with random size and automatically find Appropriate sectors by using disk allocation method (or index allocation)... Also File names should be asked from user... And we should have file table Where the starting address of each sector,file extension and file size is given..

View 1 Replies View Related

C++ :: Implementing Class To Simulate A Disk

Oct 1, 2013

So this code compiles without any problem but it is not producing the correct output. I know there's a problem in either my getBlock or putBlock functions but I can't see it.

Currently the output is "Should be 32 1s: "
"Should be 32 2s: "

There should be 32 1s and 32 2s and nothing is coming out.

#include <iostream>
#include <fstream>
using namespace std;
class Sdisk {
public :
Sdisk(string diskname);

[Code] .....

View 3 Replies View Related

C++ :: Get Live Data To Simulate Algorithm?

Apr 9, 2014

How to get live streaming of stock data from yahoo finance? Using C++. I need the code and fetch the data so I can do calculations on the price and volume or what not.

View 1 Replies View Related

C/C++ :: Can Use Packed Structure To Simulate Memory?

Oct 11, 2013

I am trying to simulate memory in C. I want to create a structure in C that will hold a 8bit opcode and a 32bit memory address. This would simulate a 40 bit instruction for my simulator.

I read in an old book that packed structs could be used for this to not waste space. What are the draw backs for using this? I am not worried about wasting space, but just looking for a simple way to access the memory instructions. Below is a sample of the structure that I want to use.

struct memory_area {
unsigned int opcode:8;
unsigned int address:32;
};

View 2 Replies View Related

C Sharp :: Run Application When Log Off In Console Application

Oct 4, 2012

i have task scheduling application which execute every 30 minute i want to keep this process when system is log off in c# console application

View 2 Replies View Related

C :: Simulate Process Of Placing CDs In CD Container Using QUEUE

Sep 16, 2014

I'm in need of the C program which will simulate the process of placing and removing CD's in CD container using QUEUE.

View 4 Replies View Related

C :: Simulate Roll Of A Dice - How To Use Rand Function

Sep 23, 2014

I saw a program in which it uses rand like this:-

d1=rand() % 6+ 1;

where, d1 is any integer. The program is to simulate the roll of a dice. The whole program is this:-

Code:

#include<stdio.h>
#include<stdlib.h>
main() {
int i;
int d1, d2;
int a[13];

[Code] .....

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved