C++ :: Send Binary Data (BMP File) To PHP Script

Oct 5, 2014

I found the following code in [URL] ....., that send .TXT files perfectly to php script in my server using Wininet, but when I insert a .BMP file, this file (.BMP) is correctly created and named in server side, but it is empty! I read that is necessary implement base64 encode for work properly, so how would?

PHP Code:

  #include <windows.h>
  #include <wininet.h>
  #include <iostream>
  #define ERROR_OPEN_FILE       10
  #define ERROR_MEMORY          11
  #define ERROR_SIZE            12

[Code] ....

View 12 Replies


ADVERTISEMENT

C++ ::  Send Binary Data Over TCP/IP

Sep 3, 2014

I am writing a client-server program in C++ using C libraries. The server listens for a connection and when one is found, it is supposed to send a binary file(an image in my case) to the client. The server is sending the binary file perfectly after opening it and reading its contents into a buffer that is dynamically allocated in the SERVER file.

The problem begins when the client file is supposed to recv() the file, I do not know how I can allocate a buffer big enough for the file to be received. I know how to use malloc() and new, I prefer malloc() for executable size customization. Assuming the file being sent is 11000 bytes(note that this is an assumption and the client can not know the file size because the file size is dynamically generated by server).

How can the client generate a dynamically allocated buffer big enough to hold 11000 bytes?
OR
How can the client store the data in a buffer using recv() without knowing the file size.

Below is part of the code that does the send()'ing and recv()'ing.

SERVER

FILE *img = fopen("img.jpg", "rb");
fseek(img, 0, SEEK_END);
unsigned long filesize = ftell(img);
char *buffer = (char*)malloc(sizeof(char)*filesize);
rewind(img);
// store read data into buffer

[Code] ....

This outputs all the binary code perfectly but it is a bug because it can't be written to a file. Is there a way to dynamically increase the buffer until all filesize is received? Certainly, buffer needs to be dynamically allocated or program crashes ...

Also one more thing, when I telnet the server from command line, telnet displays all the output perfectly as well

Maybe telnet is storing data into a buffer behind the scenes, if so, how?

View 9 Replies View Related

C :: Unable To Send Binary Data Via HTTP Response

Feb 7, 2013

I'm trying to send some binary data, such as an animated gif, via an HTTP response for a simple web server.

I am having issues having the browser close the connection after receipt of the data.

I create the header such as:

"HTTP/1.1 200 OK
Content-Length: <file size>
Content-Type: <file type>
<binary data>"

This is stored in a malloc'ed char *. To add the binary data I'm using fread: fread(request + strlen(request), 1, size, fp)

I then write 'total' bits via connfd:

write(connfd, request, total)
where total = strlen(headerRequest) + size + 3 (for ending
).

The writing seems to be okay however the image doesn't load and the browser still seems to be waiting for data.

If I added "Connection: close" to the header and closed connfd myself the page loads fine. Obviously, for efficiency purposes, I'd rather only close connfd once read() returns 0.

The header creation code is below:

======= Code:

/* Try to get file */
strcat(cwd, file);
if(endsWith (cwd, ".html") || endsWith(cwd, ".htm")) {
strcpy(fileType, "text/html");
binary = 0;
} else if (endsWith(cwd, ".txt")) {
strcpy(fileType, "text/plain");
binary = 0;

[Code]...

View 7 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C# :: Send Data To Generic Handler That Accepts JSON Data

Apr 26, 2014

I have a situation where I am accessing an ASP.NET Generic Handler to load data using JQuery. But since data loaded from Javascript is not visible to the search engine crawlers, I decided to load data from C# and then cache it for JQuery. My handler contains a lot of logic that I don't want to apply again on code behind. Here is my Handler code:

public void ProcessRequest(HttpContext context) {
JavascriptSerializer jsonSerializer = new JavascriptSerializer();
string jsonString = string.Empty;
context.Request.InputStream.Position = 0;
using (var inputStream = new System.IO.StreamReader(context.Request.InputStream))

[Code] ....

I can call the function : getUserControlMarkup() from C# but I will have to apply some URL based conditions while calling it. The contentType.typeOfContent is actually based on URL parameters.

If possible to send JSON data to this handler then how to do that. I am trying to access the handler like this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Common.host + "Handlers/SideContentLoader.ashx?typeOfContent=1&UCArgs=cdata");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

But its giving NullReferenceException in Handler code at line:

ContentType contentType = jsonSerializer.Deserialize<ContentType>(jsonString);

View 1 Replies View Related

C :: Converting Binary Data In A Txt File Into HEX

Apr 17, 2013

I'm not the best at C but I'm trying to write a C function that basically opens a text file with assembler language does a syntax error check on it and then converts the binary data into hex.

This is my code so far:

Code:

#include <stdio.h>
#include <string.h>
int main(void)
{
FILE*fname;
char prompt;
char filename[15];
char text[100];
printf( "Please enter the name of the file you wish to open: " );

[Code]...

View 6 Replies View Related

C++ ::  writing Binary Data On Txt File?

Aug 16, 2013

I a want to write a code to convert a string into binary data for that i wrote a code its working perfectly but there is one problem , some of the binary data is written in 7bit and i want to convert it to 8 bit by adding 0 to the last.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

View 2 Replies View Related

C :: Writing Binary Data Or Reading From A File

Mar 6, 2013

I am having problems either writing data to a binary file or reading from the file. Through the process of elimination I am posting the code where the data is written to file to see if I can eliminate that as an option. I know the data is being processed correctly because, through the use of another function, I can view the data.

I also know that fwrite must be including some padding because the file size ends up being 576 bytes after it is written instead of 540 bytes (the size it would be if no padding is used). Here is my struct:

Code:

typedef struct {
char teams[25];
float wins;
float losses;
float pct;
int runsScored;
int runsAgainst;
} STATISTICS;

Here is where I initialize it:

Code:
STATISTICS stats[12] = {
{"Anaheim Arrays", 0.0, 0.0, .000, 0, 0},
{"Pittsburg Pointers", 0.0, 0.0, .000, 0, 0},
{"Indianapolis Integers", 0.0, 0.0, .000, 0, 0},

[Code] ....

And here is the function that writes my data. The sA array is only used to change the scheduled games based on the variable week.

Code:
void schedule(STATISTICS stats[]) {
FILE *f;
int sA[12], week = 0, runsPerGameA = 0, runsPerGameB = 0, runsAgainstA = 0, runsAgainstB = 0;
int index, a = 0, b = 1, i = 0;

[Code] .....

View 13 Replies View Related

C++ :: Create A Binary File Based On HEX Data

Apr 24, 2013

I want to create a binary file based on some hex data :

Ex Input Hex :54313032202020303030

Out put like :6      

View 2 Replies View Related

Visual C++ :: Read JPG As Binary In MFC App And Send To JavaScript Function In HTML Page?

Sep 6, 2013

I am writing an MFC app in Visual Studio 2012 that will open a JPG file as binary and read all the contents to a CString.

I am able to read it to a std::Vector, but that doesn't work much as i need to pass all the binary content as a MFC CString to another function.

More Update:

Let me explain the problem a little more deeper.

I am trying to call a JavaScript (JS) function in a HTML page and then want to pass the binary date. The C++ function that calls the JS is given below.

bool CallJavaScript(const CString strFunc,CComVariant* pVarResult);

The 1st argument is the JS Function Name and 2nd is the one to pass the Binary Data. 1st argument works fine as i am able to call the JS fucntion called "LoadImage" without any problem. Problem is with 2nd argument that's supposed to take the Binary data of the JPG file.

If i try to pass a std::Vector or std::string then it will give me an error.

But it's happy if i pass CString. But then with CString there's a problem with NULL characters.

Actually my plan is to pass the binary of a JPG to a JS function and let it display the JPG in the HTML page.

Can i typecast a Vector or std::string to a CComVariant*?

View 3 Replies View Related

C++ :: Writing Text Data To A Binary File With Fstream

Jul 9, 2014

fstream ifs;
ifs.open ("data.str", ios::binary | ios:ut);
char *data1 = "data1";
char *data2 = "data2";
ifs.write(data1, strlen(data1));
ifs.write(data2, strlen(data2));

when i this,data2 is not going under data1, i thought each write starts on a new line?

View 4 Replies View Related

C++ :: Binary File - Replace Data At Specific Point?

Nov 28, 2014

I'm making a binary file that has 100 "empty spaces", and then I want to rewrite specific place with info, however it always writes the info at the end of the file, no matter what I try to get position before I call write() it tells me correct position...

#include <Windows.h>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>

[Code].....

View 5 Replies View Related

C :: Program To Read Binary Data And Print It - File I/O Error

Mar 14, 2013

Objective of this program is to read binary data from a file and print it.

Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;

[Code] .....

But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!

I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.

View 4 Replies View Related

C++ :: Writing Data On A File In Binary Mode Multiple Times

Oct 20, 2013

When you have to write data on a file in binary mode multiple times (without closing the file), is the put pointer left where you ended writing the last time, or do you have to use tellp() or seekp() again and again to make sure you write at the right place?

I would have the same question about the get pointer, does he stay in place after you're done reading something (without closing the file, of course), or do you have to set it back at the right place with seekg() ??

View 5 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# :: Cannot Send Data From Client To Server

Oct 26, 2014

i am making a client server application but the problem is that i cannot send data from CLIENT to SERVER , but i can receive data from SERVER to CLIENT ... Below is mt client and Server code and i also have attached both client and server files...

CLIENT CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace asynclient {

[code]....

View 3 Replies View Related

C/C++ :: How To Send Post Data Using Httpsendrequest

Sep 8, 2014

I'm trying to send a simple text string using httpsendrequest, everything works fine, the string is sent but I don't know how to retrieve it in the PHP server. Also when I use internetreadfile, the dwBytesRead is 0 meaning that there is no response from the server though the application works fine. This is the code that I have so far.

#define _WIN32_WINNT 0x600
#include <stdio.h>
#include <wininet.h>
#define BUFLEN 200
static const char *acceptTypes[] = {"application/x-www-form-urlencoded", NULL};
static const char *postData = "teststr=Hello+world&testval=42";
int main() {
HINTERNET hSession, hConnect, hFile;

[code].....

View 1 Replies View Related

C :: Parsing Binary Data File By Casting A Buffer - Accessing Double From Struct

Jan 4, 2014

I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.

Code:

typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;

If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...

Code:

typedef struct example {
double d;
}

example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);

View 7 Replies View Related

C++ :: Turn Binary File Data Into Unsigned Character Array For Inclusion In Executable

Jul 10, 2013

So I wrote a program to turn a binary file's data into an unsigned character array for inclusion in an executable. It works just super.

I'm wondering how I can write a program that will perform this operation on every file in a directory and all it's sub-directories so that I can I can include everything I need all at ounce.

View 9 Replies View Related

C++ :: Streambuf For Socket - Send / Receive Data

Mar 27, 2014

I am trying to make a streambuf for a socket, which will use either WinSock or POSIX sockets depending on OS. I understand about how to send and receive data via sockets, but I don't really understand how to put that into a 'streambuf'. What functions do I need to override?

View 7 Replies View Related

C# :: How To Send And Receive Data From Serial Port

Aug 13, 2014

private void button1_Click(object sender, EventArgs e) {
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;

[Code]...

In my project i have a serialport control and a button, there is no error but i want to know how actually this works, i want to send and recieve the data from the serial port don't know how to do it..

View 9 Replies View Related

C :: Standard USB Protocol To Follow To Send Data To Embedded Board (and Vice Versa)

Mar 13, 2013

Is there any standard USB protocol which i can follow to send data to my embedded board(and vice versa). I have no clue on USB programming using c,is there any example code i could follow,

View 4 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C/C++ :: How To Send PPM To A Function In Another File

Apr 7, 2015

I have an assignment where I have to alter a ppm image and send it to a function in another file to print the new altered version.

#include "transform.h"    
int main (int argc, char *argv[])  {  
    // declarations here
    FILE *inFile;      
    // open input file 
    inFile = fopen("tiger.ppm", "r")

[Code] ....

View 1 Replies View Related

C++ :: Send String As Argument To TXT File

Apr 8, 2014

I have a function which send a string as argument to a txt file, like the following:

void Fprint(... ofstream& myfile, const string a, const int b)
......
myfile << "name: " << a << " age:" << b << "" << endl;
......
}

However, my IDE (msvc12.0) popup an error about the << before a, by citing "No operator matches these operands.

View 2 Replies View Related







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