Just as a pre-project survey, you do not have to create your own SOAP server, but at least I am interested in it now.
First, be familiar with the application of tcplistener on PDA. The following example is a demo of the time server. The server listens for incoming connections on Port 13. Once the connection to the client is listened, the sending time is sent to the client, and the connection is closed.
Servers are PPC-based applications Program It can run on both the PC and the PDA. Note that when the PDA is connected to the PC, the network connection of the PC will come out one more, this is used to communicate with the PDA. It is equivalent to another subnet. Pay attention to its IP address. The source code is as follows: Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using System. net;
Using System. net. Sockets;
Using System. IO;
Namespace Pdatimeserver
{
Public Partial Class Form1: Form
{
Private Bool Done = False ;
Tcplistener listener = Null ;
Public Form1 ()
{
Initializecomponent ();
}
Private Void Button#click ( Object Sender, eventargs E)
{
Listener = New Tcplistener (IPaddress. parse (combobox1.text. Trim ()), 13 );
Listener. Start ();
Done = False ;
While ( ! Done)
{
Int Index = Listbox1.items. Add ( " Waiting for connection " );
While ( False = Listener. Pending () && False = Done)
{
Application. doevents ();
}
If (Done)
Break ;
Tcpclient Client = Listener. accepttcpclient ();
Listbox1.items [Index] + = " Connection accepted. " ;
Networkstream NS = Client. getstream ();
Streamwriter = New Streamwriter (NS );
Writer. Write (datetime. Now );
Writer. Close ();
NS. Close ();
Client. Close ();
}
Listener. Stop ();
Listbox1.items. Add ( " Stop listening " );
}
Private Void Button2_click ( Object Sender, eventargs E)
{
Done= True;
}
Private Void Form1_load ( Object Sender, eventargs E)
{
IPaddress [] iplist = DNS. gethostbyname (DNS. gethostname (). Addresslist;
Foreach (IPaddress IP In Iplist)
{
Combobox1.items. Add (IP );
}
Combobox1.selectedindex = 0 ;
}
}
}
To facilitate the test, the client is based on Windows and cannot run on the PDA. Its function is to connect to the specified server and obtain the time. The source code is as follows: Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using System. net;
Using System. net. Sockets;
Using System. IO;
Namespace Timeclient
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}
Private Void Button#click ( Object Sender, eventargs E)
{
Tcpclient Client = New Tcpclient ();
Client. Connect (combobox1.text. Trim (), 13 );
Networkstream stream = Client. getstream ();
Streamreader = New Streamreader (Stream );
Textbox1.text = Reader. Readline ();
Reader. Close ();
Stream. Close ();
Client. Close ();
}
Private Void Form1_load ( Object Sender, eventargs E)
{
IPaddress [] iplist = DNS. gethostbyname (DNS. gethostname (). Addresslist;
Foreach (IPaddress IP In Iplist)
{
Combobox1.items. Add (IP );
}
Combobox1.items. Add (IPaddress. parse ( " 169.254.2.1 " ));
Combobox1.selectedindex = 0 ;
}
}
}