473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to send many images through socket ?

hello guys i have written a socket witch send an image 256x256 and now i want to send many images and i don't know what loop to write to make the socket after have sent the first image to send another and not to write the same program many times for every image ......

this is the part that read the binary image


Expand|Select|Wrap|Line Numbers
  1. if( !(fp=fopen("Anemos.bmp","rb")))
  2.     {
  3.             printf("Unable to load bin file: %s...\n","Anemos.bmp");
  4.       }
  5.  
  6.  else
  7.     {
  8.         cnt = 0;
  9.         im_row=0;
  10.         im_col=0;
  11.         while (!feof(fp)) {
  12.             tc = fgetc(fp) & 0x0ff;
  13.  
  14.             if (cnt==10) offset=tc;
  15.             if (cnt==18) w1=tc;
  16.             if (cnt==19) w2=tc;
  17.             if (cnt==22) h1=tc;
  18.             if (cnt==23) h2=tc;     
  19.         if (cnt==28) bpp=tc;   
  20.             if ((cnt==30)&&(tc>0)) printf("ERROR!! Cannot Handle BMP files with Compression!!!\n");
  21.             if (cnt==53) break;
  22.  
  23.             cnt++;
  24.                 }
  25.     }
  26.  
  27.     width  = w1+w2*256;
  28.         height = h1+h2*256;  
  29.  
  30.        int  BMPRES_X = height;
  31.        int  BMPRES_Y = width;
  32.  
  33.     padd = 0;   
  34.         printf("W:%d, H:%d   Image Data Starts at:%d with %d bits/pixel \n",width,height,offset,bpp);
  35.           for (im_row=0;im_row<height;im_row++)
  36.         {
  37.             for (im_col=0;im_col<width;im_col++)
  38.             {
  39.                 tc = fgetc(fp) & 0x0ff;
  40.                 tmpim[(im_col*height+height-im_row-1)*3+2] = tc;
  41.  
  42.                 if ((im_col%32==0)&&(im_row%32==0)) printf("%02u",tc/10);
  43.  
  44.                 tc = fgetc(fp) & 0x0ff;
  45.                 tmpim[(im_col*height+height-im_row-1)*3+1] = tc;
  46.  
  47.                 if ((im_col%32==0)&&(im_row%32==0)) printf("%02u",tc/10);
  48.  
  49.                 tc = fgetc(fp) & 0x0ff;
  50.                 tmpim[(im_col*height+height-im_row-1)*3+0] = tc;
  51.  
  52.                 if ((im_col%32==0)&&(im_row%32==0)) printf("%02u-",tc/10);
  53.             }
  54.             if (im_row%32==0) printf("\n");
  55.  
  56.             for (i=0;i<padd;i++) 
  57.             {
  58.             tc = fgetc(fp) & 0x0ff;
  59.         }
  60.     }
  61.  
  62.  
  63.  
  64. fclose(fp);
please help....thanx
Jun 25 '12 #1
2 6492
johny10151981
1,059 1GB
Simply you can close the socket after you send one image.

or you can think of separating header

such as
Expand|Select|Wrap|Line Numbers
  1. fileName:current_image.ext\r\n
  2. fileSize:image_file_size\r\n
  3. \r\n
  4. ... file data
  5. ... file data
  6.  
other end will read file name, will read file size when it would get two \r\n it will start reading the file. very common in HTTP :)
Jun 26 '12 #2
hii johny10151981 i have the same problem can you explain me that you mean with the code or some link to see something same ? i have tried to send image by image i write the same code for every image i send but finaly i receive the same image many times ....
Jun 28 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
4
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
4
by: david | last post by:
hello, I have a client/server application. the server capture picture from webcam and send it to every client connected to it.the network part works good and the capture from webcam too. I...
14
by: ahlongxp | last post by:
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides...
4
by: surja | last post by:
Hi all, I want to send some image files from my desktop to mobile . How I can I do that without e-mailing . anybody can help me with a reference for codes or any tutorials. regards surja
4
by: gvijayaratnam | last post by:
Hi All, I have a fn prototype as follows void print ( char *Buffer, usigned long bufferSize, int chunkSize ); This fn will accept binary file buffer and the buffer size and the chunk size,...
1
by: cookspyder | last post by:
So I have this script and it works great at sending things over a socket after tailing a file. The problem seems to be when the recieving end is not available the program crashes. Is there a way to...
3
by: Hanzis | last post by:
Hi, I make program, which sendig printscreen on remote PC and i have a problem. I don't know how to send an image from remote PC on the local PC. I programm in RAD Studio 2009 and for internet...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.