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
ADVERTISEMENT
May 11, 2013
I want to send data from a file via winsock. The problem is that the only first line in the file is send.
Client
#include <iostream>
#include <winsock2.h>
#include <fstream>
#include <string>
#pragma comment(lib,"ws2_32.lib")
#define SERVER "127.0.0.1" //ip address of udp server
[Code] ....
View 2 Replies
View Related
Oct 31, 2013
Client:
Code: ....
string cmd = "dir c:filequeue > ";
string outputFilePath;
outputFilePath.append(getTempPath());
outputFilePath.append(" est.txt");
cmd.append(outputFilePath);
system(cmd.c_str()); // dir c:filequeue > %temp% est.txt
string content = get_file_contents(outputFilePath.c_str());
send(s, content.c_str(), content.length(), 0); I'm executing the "dir" command to get a listing of Folders/files of one Folder. Then I read the Output of the file and send it over winsock to the Server.
Now, the Problem is, I don't know how I can handle the recv properly, cause I have to set the buffer size without knowing, how much data is actually transfered. Sometimes maybe no files are in c:filequeue, sometimes a 100k.
So I tried to make recv as a Loop:
Server:
Code: ...
while (rc != SOCKET_ERROR) {
printf("
#");
gets(buf); //please no discussion about gets, I will Change this later ;)
if (strcmp(buf, "ls") == 0){
send(connectedSocket, "LIST", 4, 0);
[Code] .....
now it works, but as the recv blocks, it will never leave the Loop, even when the Transfer is finished.What should I do?
I believe I could make unblocking sockets, but that's a bit complicated. Isn't there an easier solution, with malloc'ing the buffer or a Signal when to leave the recv Loop?
View 3 Replies
View Related
Mar 13, 2015
I am currently trying to send a x264 nal unit using WINSOCK with a reliable multicast socket. It isn't decoding properly, and my initial thought is I am not receiving all the bytes correctly. I was hoping some fresh eyes can provide insight on errors or any improvements. I have seen some topics about this subject, and they showed sending entire structs with the socket. However, I am concerned about endianess so I am trying to stay away from that approach. I have commented out the decoding part, until I am confident that I am receiving the nal unit properly.
Server:
#include <WinSock2.h>
#include <WS2tcpip.h>
#include "wsrm.h"
#include <Windows.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include "x264Encoder.h"
View 4 Replies
View Related
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
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
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
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
Jul 23, 2014
If I have a text file named, stuff at a specified path in the c : drive, how do I send the contents of this file to another computer using the Internet?
View 5 Replies
View Related
Apr 21, 2014
How to send a keystroke or a mouse event to another running process in Ubuntu? I want to write a C program that reads data from the USB port sent by AVR Micro Controller board continuously.In response to that it checks the data received and sends a command to another process running on the computer? Example,when the program reads 101 from the USB port it sends left mouse button down to the VLC media player window that is currently running?
View 1 Replies
View Related
Dec 22, 2014
When server send data then client receive that data, in C# windows services where data receive continuously (Using IP Address and port number) . This below code writing in console application . i want implement same logic in windows service side. but i want data receive continuously.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
[Code]....
Above code write in console application, same logic implementing in windows service, but i want data receiving continuously
View 3 Replies
View Related
Feb 10, 2015
I have a header file that declares some fields as private, I then have a class that I need to compare two of the objects' information for equality but neither of them are the calling objects. I cannot alter the header file. How would I go about comparing private data fields? I will enter a brief bit of code for clarity.
Code: // Header File
// stuff.h
class stuff
{
private:
int* arr[20];
int size;
};
bool equal (const stuff& a, const stuff& b);
[code].....
View 11 Replies
View Related
Jan 9, 2014
I have a small class with a static int data member. I want to zero init it. I am thinking that making a .cpp file with only one line seems too much, isn't it?
So, can I do it inside the the header file? The variable is going to enumerate how objects were created (so any alternative will do).
View 7 Replies
View Related
Jun 11, 2013
I'm trying to read from a header file to take the image dimensions and other variables but I don't understand how to iterate through the "key" so it saves each line.
This is what the header file will always look like:
!INTERFILE :=
!imaging modality := nucmed
!version of keys := 3.3
;
!GENERAL DATA :=
[Code].....
Ideally it would just skip the keys that aren't wanted and keep moving through the lines. Should there be a for loop for the key (and if so, how does that work with pointers?) or should this method just be scratched...
View 6 Replies
View Related
May 29, 2014
I have make a code for simple chatting for single client but i want to make it for multiple client. what i need to modify in the code?
server.c
int main(int argc, char *argv[]) {
struct sockaddr_in localaddr,remoteaddr;
SOCKET s,ns;
char send_buffer[80],receive_buffer[80];
int n,bytes,addrlen;
memset(&localaddr,0,sizeof(localaddr));
[Code] .....
View 13 Replies
View Related
Oct 25, 2013
I'm trying to understand winsock with c++. Let's assume I have a 2 working applications, one is the client and one the server:
Client: I can enter a command, for example chat or filetransfer, it will then switch into this specific mode where I can enter commands like uploading a file, send a message etc.
Client
Code: ....
while (rc != SOCKET_ERROR) {
printf("
#");
gets(buf);
if (strcmp(buf, "CHAT") == 0){
// start chat mode
[Code] .....
I'm in a recv/send loop and I'm using streams...so basically all the data is being sent/received there. Now, if I want to upload a file, I send a FILETRANSFER String to the server. Then I will probably need another loop that receives file requests from the client. The server will need more details about the file, like the path, name, size...
Now, my question is, what's the best practise for something like that? I'm having problems understand how I can send 3 different values from the server to the client and how he will receive them in the right order store them in variables. And also, after sending something to the server, in some cases, the client will have to wait for the server to answer.
Is there a good example of a similar application?
View 3 Replies
View Related
Jul 24, 2013
Code:
#include <algorithm>
#include <winsock.h>
void some_func() {
int result = std::min (0, 16384);
}
Okay, but the above code consistently gives me error C2589: '(' : illegal token on right side of '::'. I'm building with VC8. If I don't #include <winsock.h> the code compiles correctly but it doesn't matter if I #include <winsock.h> before or after including <algorithm>
I guess it might be due to one of my #defines but I've tried the code in a very minimal program and I still get the error.
View 7 Replies
View Related
Nov 21, 2013
send(sConnect, (userinput, key), 256, 0);
sConnect is already predefined as a socket
Key is a character array of [32]
Userinput is a character array of [256]
How can you send both of them at the same time using the send function without having to create a separate connection?
View 1 Replies
View Related
Jun 16, 2013
My problem is that I've created a Client and Server program in which they communicate. The Client is an SDL Application that allows you to play as a movable character IF YOU ARE CONNECTED TO THE SERVER. If not, You're unable to play. THIS WORKS!
However, Only one client is able to play on my server?? Anyone elses' window freezes and they are not allowed to play (As if not connected to the server). Here is my server code.
Code:
#include <iostream>
#include <winsock2.h>
#include <vector>
#include <process.h>
#include "Included/pthread.h"
#define MAX_THREADS 5
bool gamerunning = true;
[Code] ....
I'm having troubles allowing more than one client to play on the server.
View 2 Replies
View Related
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
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
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
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
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
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
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