File Transfer over socket between Windows Mobile Devices

Source: Internet
Author: User
Tags filetime

The article "using WiFi to build an ad-hoc Network on Windows Mobile" describes how to use wifi to build an ad-hoc Network on Windows Mobile. Because ad-hoc networks have established point-to-point wireless links, devices can be interconnected without access points, which is convenient, flexible, and configurable. In the text Im over socket between Windows Mobile devices, this article describes how to use sockets between Windows Mobile devices to send and receive messages in real time after a point-to-point Wi-Fi wireless connection is established. This articleArticleThe following content will be introduced, that is, after a point-to-point Wi-Fi wireless connection is established, files are transmitted between Windows Mobile devices using sockets.

1. ApplicationProgramIt can be divided into server and client. Because it is a demo program, the simple file transmission function is implemented here, and it does not involve any depth, such as resumable data transfer. After a connection is established between the server and the client, the user-selected files are transmitted to the client, and the transmission ends.

2. the development environment is Visual Studio 2008 + Windows Mobile 2003 for Pocket pc sdk + Windows Mobile 6 pro SDK, which is developed using MFC.

3. when creating a new project, select Windows Sockets in the advanced features option to add socket support (the figure is shown in the IM over socket between Windows Mobile devices article ).

4. Add the structure of the file information to the header files on the server and client:

Typedef   Struct _ Socket_stream_file_info {tchar szfiletitle [2, 128]; // File title name DWORD dwfileattributes; // File attributes Filetime ftcreationtime; // File Creation Time Filetime ftlastaccesstime; // Last Object Access time Filetime ftlastwritetime; // Last modification time of the file DWORD nfilesizehigh; // High dual-character file size DWORD nfilesizelow;// Low dual-Text of the file size DWORD dwreserved0; // Reserved DWORD dwreserved1; // Reserved } Socket_stream_file_info, * psocket_stream_file_info;

 

5. Add a button on the server. In the Click Event of the button, select a local file and send it to the client. In the Add button on the client and the server IP address input box, after entering the Server IP address, click the button to receive the files sent from the server.

6. csocket is used for communication. For more information, see msdn: csocket class. The methods in csocket are blocking. Therefore, when sending and receiving large files, the user will feel like a dead machine. In order to prompt the user, we should add the progress bar for sending files. So how to implement the file transfer progress bar? Because we transmit data in segments, that is, 1024 bytes are sent each time, and the total size of the file is known. Therefore, when sending or receiving the file content, we can count to know the completion percentage and display the relevant information on the progress bar. (Note: Only the file size is used here.)

7. KeyCodeAs follows:

Server:

 
Uint dwread = 0;While(Dwread <streamfileinfo. nfilesizelow) {byte * Data =NewByte [1024]; uint DW = myfile. Read (data, 1024); sockrecv. Send (data, DW); dwread ++ = dw;// Set progress barMyctrl. setpos (dwread * 100/streamfileinfo. nfilesizelow);} myfile. Close ();

Client:

 
Uint dwread = 0;While(Dwread <streamfileinfo. nfilesizelow) {byte * Data =NewByte [1024]; memset (data, 1024); uint DW = sockclient. Receive (data,); destfile. Write (data, DW); dwread + = dw;// Set progress barMyctrl. setpos (dwread * 100/streamfileinfo. nfilesizelow );}

8. To better prompt users, we can add the "System Busy" prompt during file transfer/file receiving, that is, we can use the following code pairs to achieve this:

// Set wait sursorSetcursor (loadcursor (null, idc_wait ));// Close Wait sursorSetcursor (null );

9. Code test. Use wifi to build an ad-hoc Network on Windows Mobile. Run the client program on the Windows Mobile 2003se for Pocket PC and the server program on the Windows Mobile 6 Professional device, as shown in:

Figure 1: Client Interface

Figure 2: server-side program open file Interface

Figure 3: server-side File Sending completion page

Figure 4: client-side file receiving completion page

Figure 5 Location of the received file on the client

Reference link:

1. Use wifi to build an ad-hoc Network on Windows Mobile

2. Im over socket between Windows Mobile Devices

3. csocket class

 

Source codeDownload the project: tcpfile.rar (Visual Studio 2008 + Windows Mobile 2003 for Pocket pc sdk + Windows Mobile 6 pro SDK)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.