我用的是vs2005
文件 - 新建 - 项目 - 控制台应用程序
using System; using System.Collections.Generic; using System.Text; using System.Net.Sockets; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { TcpListener listener; try { listener = new TcpListener(8888); //说此方式已过期,⊙﹏⊙b汗 } catch (Exception ex) { Console.WriteLine(ex.Message); return; } listener.Start(); Console.WriteLine("服务器启动,等待客户端连接."); bool loop = true; while (loop) { Socket s = listener.AcceptSocket(); NetworkStream ns = new NetworkStream(s); StreamReader reader = new StreamReader(ns); string result = string.Empty; try { result = reader.ReadLine(); Console.WriteLine(result); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } }
FlexBuilder 3。
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0,1.0]" backgroundGradientColors="[#E7A8E2,#FFFFFF]"> <mx:Script> <!--[CDATA[ import mx.controls.Alert; private var xmlConn:XMLSocket; private function connectionServer():void { xmlConn = new XMLSocket(); xmlConn.connect(txtAdr.text,int(txtPort.text)); } private function onSend():void { xmlConn.send(txtData.text + "/n"); } ]]--> </mx:Script> <mx:Label x="138.5" y="96" text="端口:" fontSize="12"/> <mx:Label x="138.5" y="70" text="地址:" fontSize="12"/> <mx:TextInput x="178.5" y="70" width="223" text="127.0.0.1" id="txtAdr"/> <mx:TextInput x="178.5" y="96" width="223" id="txtPort" text="8888"/> <mx:TextArea x="138.5" y="122" height="120" width="263" id="txtData" fontSize="12"/> <mx:Button x="243.5" y="250" label="发 送" fontSize="12" click="connectionServer();onSend()"/> </mx:Application>