Exploration of pda soap server (1)

Source: Internet
Author: User
Tags getstream
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 ;
}
}
}

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.