Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, I have a project that requires sending desktop images of the client to the server. The server must handle all incoming connection and to every client, a new windows form will appear that has a picture box in it whereas this picture box contain the images of that client. Please help me... Thanks in advance.

What I have tried:

I already tried searching to this problem, but most solution uses a synchronous communication between server and client.
Posted
Updated 17-Mar-16 23:04pm
Comments
Mycroft Holmes 18-Mar-16 3:43am    
This is wrong, a server application rarely has a UI. A server should store the images and the client is used for display

I posted Client Side Code For an Example. may it would be useful.
C#
Stream imageFileStream = File.OpenRead("YourFullFilePath");
           byte[] byteArray=new byte[imageFileStream.Length];
           imageFileStream.Read(byteArray, 0, (int)imageFileStream.Length);
           TcpClient client = new TcpClient("YourServer",8080); //8080 is the port where server is running.
           NetworkStream network = client.GetStream();
           network.Write(byteArray,0,byteArray.GetLength(0));
           network.Close();
 
Share this answer
 
Comments
Member 12070650 18-Mar-16 3:10am    
How about the server side sir... I hope that it could handle multiple client..... And the received image will be displayed in a picture box... Can you give me an example sir???
Hi! hope you getting idea by my example. here I am giving you server side example.
Server side code can be like :

C#
TcpListener ServerforTCP = new TcpListener(8080);
           ServerforTCP.Start();
           while (true)
           {
               Socket socketToHandleRequest = ServerforTCP.AcceptSocket(); //accept client request.
               NetworkStream network = new NetworkStream(socketToHandleRequest);

               int readPoint = 0;
               int chunkSize = 1024;
               byte[] data=new byte[chunkSize];
               lock (this) //to handle multiple client call issue
               {
                   Stream fileForWrite = File.OpenWrite("FilePathWithFileNameWhereYouWantTosaveYourJPGFILE");// ex :D:\\File.jpg
                   while (true)
                   {
                       readPoint = network.Read(data, 0, chunkSize);
                       fileForWrite.Write(data,0,readPoint);
                       if(readPoint==0)
                       {
                           //end of the file read from client. you can break the loop.
                           break;
                       }
                   }
                   fileForWrite.Close(); // Must Close.
               }
               socketToHandleRequest = null; // assign null to release memeory.
               System.Threading.Thread.Sleep(1000);
           }



Thanks!.
 
Share this answer
 
Hi! this is my first answer so please help to make my answer skill better. I just try to express things in brief.

Have you try with stream ?
in short I want to ask you that have you try to read stream of your image file into byte[] and send that file to server?
same you can do this in reverse order at Server side.
get byte[] and save that byte[] with image file extension.

have you tried this? if not then let me know I will post demo here.
Thanks.
 
Share this answer
 
Comments
Member 12070650 18-Mar-16 3:08am    
How should i do it sir. I am new to .NET socket and the only thing that i have tried is a synchronous tcp connection. sending and receiving images is fine in a synchronous way, but when handling multiple connection, i don't know anymore.. can you give me some example at least catering multiple client that send images continuously...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900