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 .
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?
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?
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.
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:
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.
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?
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.
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
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 !!
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] ....
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();
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.
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:
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 } }
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.
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.
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.