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


ADVERTISEMENT

C :: Sending Numbers Through Sockets

Nov 1, 2013

I want to write a program(s) so that the client sits and waits for a scanf to receive an int, then send to server, server then receives the int, processes it, then goes back to sit and wait for new input. to start with, where do i start! server side, or client side? and also what order do i have to go in my program before the loop to set up the socket, and listen? and then what gets looped to keep the connection open and wait for new receive?

View 4 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

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 :: Sockets Using Poll

Jul 13, 2013

Until recently I have been using select() to wait for activity on file descriptors, however this seems less efficient than poll. I rewrote the program using poll:

Server:

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/types.h>
}

[code].....

View 11 Replies View Related

C :: Send HTTP With Sockets

Apr 9, 2013

I'm connecting to my website through sockets, like this:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <string.h>
int main(int argc, char *argv[]) {
WSADATA wsadata;
if (WSAStartup(MAKEWORD(2,2), &wsadata) == -1)

[Code]...

I want to send GET to a certain web page. How can I do that?

View 2 Replies View Related

C# :: Created A Simple Basic Program That Uses Sockets

Feb 22, 2012

I have created a simple basic program that uses sockets but it can only handle one connection, how do I make it so it handles multiple connections?

Server code:

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
}

[code]...

View 5 Replies View Related

Visual C++ :: Use Windows Sockets To Send Email?

Jan 26, 2013

I have struggled to send email from my MFC applications using severl methods:

1) http via my server - works but limited
2) M$ Outlook automation - works but not easily interchangeable between machines
3) Windows Sockets - available information simply too complicated
4) Purchase an ActiveX control - I hate black box solutions and am too cheap

I have looked at P. J. Naughter's class
CPJNSMTPConnection v2.99
An MFC class to encapsulate the SMTP protocol
[URL]

This approach requires the implementation of OpenSSL which turns out to be nothing short of a nightmare to install (so I never got it to run). I am looking for an example of an application that utilizes SMTP via Windows sockets api.

View 6 Replies View Related

C# :: How To Send Message To Multiple Sockets In List Object

Oct 7, 2012

Have tried to track down the delay? Which function takes that long? Have you printed some logs or measured the time of the functions? No I am not sure how to do that! I debugged it but i didn't see any difference! I definitely think its the logic in the receive code that's "inefficient" what do you think about that? Do you think there's a more efficient way of receiving messages and sending them? Because what I am doing is receiving one then calling send and sending that message out to all users then receiving another one then calling send and sending it out to all users and repeating that process till all the messages are sent, both methods are using a loop to send to all users. DO you think i should receive all messages then send them all out at once? or is that less efficient?

View 4 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 :: 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 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 :: 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

C# :: Sending File Over TCP

Sep 16, 2014

why this code works only for file of smaller data. When I try to send for istance a image, the image arrive corrupted.

Client:

//read all file
byte[] vett = File.ReadAllBytes(s);
//read filename

[Code]....

View 11 Replies View Related

C++ :: Sending Constants As Parameters

Nov 21, 2013

What's the problem with the following:

Code:
#define K 3;
int max(int a, int b) {
return a>b? a : b;
} int main() {
cout<<max(K, K+3);
return 0;
}

Why is it not allowed, and how is it different from:

Code:
int max(int a, int b) {
return a>b? a : b;
} int main() {
cout<<max(3, 3+3);
return 0;
}

View 3 Replies View Related

C :: Sending Matrix Over UDP Socket

May 18, 2014

I want to apply program to send matrix from client and server ,and return back a processed matrix ..

How I can do it using UDP ,it was easy to use tcp for that!?

View 3 Replies View Related

C :: Sending Integer Via Socket

Dec 18, 2014

Verify my Method . I am not getting expected output ..

Code:

int Amount=500;
send(newSocket,Amount,4,0);
close(welcomeSocket);
recv(clientSocket,Amount,4,0);
// Amount= ntohl(Amount);
printf("Data received: %d",atoi(Amount[0]));

View 5 Replies View Related

C++ :: Sending A String To Program?

Jul 21, 2013

I have a project, to make a program that spams chat programs. I've been trying to figure out how to send a string to an open program such as notepad, or a chat window. I know how to simulate keystrokes but I have yet to figure out or find out any way of sending a string to a program. pseudo code:

int main() {
string a;
int howManyTimes;
cin >> a;
cin >> howManyTimes;
//user enters "pizza"
for(int i = 0; i < howManyTimes; i++) {
//now I want "pizza" to be sent to the program keystroke enter or whatever the correct syntax is sleep
} }

View 1 Replies View Related

C++ :: Template Of Sending Text

Mar 1, 2013

I am writing some code to send text to a third part software. Basically each sending looks like this:

p << "set terminal eps
";
p << "set output '07.eps'
";
p << "plot '-' using ($1 == 0 ? NaN : $1) with lines linecolor 2 title 'comparison ratio',
'-' using ($1 == 0 ? NaN : $1) with lines title 'comparison ratio'
";
p.send(TOex_ar).send(TOnew_ar);
p << "set terminal wxt 7
";
p << "plot '-' using ($1 == 0 ? NaN : $1) with lines linecolor 2 title 'comparison ratio',
'-' using ($1 == 0 ? NaN : $1) with lines title 'comparison ratio'
";
p.send(TOex_ar).send(TOnew_ar);

Each time I have to change the number "07" and "7";decide to add or not the following parts: "using ($1 == 0 ? NaN : $1)", "with lines", "linecolor 2";and write the title 'comparison ratio' and the name of data to send "TOex_ar" and "TOnew_ar".Since I have to do this kind of thing 50 times in my code, and it is in the form of text, I am wondering whether in C++ we can write a template or function to simplify the program, just to input the changing parts.

View 3 Replies View Related

C# :: Sending Messages To Log In And Password

Apr 20, 2014

I wanted to make an program which is sending messages to log in and password, but instead of message it gives me "System.Windows.Forms.TextBox, Text: AND HERE MY TEXT I WANTED.

View 9 Replies View Related

C# :: Sending X-AMF Type Packets

Jan 10, 2015

create BOT that adds friends on one of Chat websites.

Im using C#

On website there is a button that adds user to friends

<li class="friend"><a href="javascript:void(0)">Add Friend</a></li>

I captured packet that is sended to server then that button is clicked

POST (info hided)/amfgateway.php HTTP/1.1Host: (info hided)
Connection: keep-alive
Content-Length: 52

[Code].....

It apears that this is AMF(Action Message Format) type packet Content-Type: application/x-amf it is in binary and this complicates things a little because I cannot send it with regular httpwebreqeuest class(Or I think so)

I used Fiddler4 with AMF plugin to check what data was passed with that packet

It apears that these numbers under content / 0 are User-id that is needed to add user to friends

I did a research with little success finding any usefull examples. I just found that there is a library for FLEX/FLASH remoting called fluorinefx and this should do the job but when I opened documentation it seems little too complex for me.

View 2 Replies View Related







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