C#.NET实现客户端服务器信息交互,怎么做???

来源:百度知道 编辑:UC知道 时间:2024/09/24 13:14:45
是C/S的,不要B/S的,谢谢,要一个简单的实例,以前没做过这个!
谢谢各位 高手

使用
using System.Net;
using System.Net.Sockets;

一下是一个服务段的代码,你可以Telnet到这个例子上去,想必下面你应该都能看懂,Client段的代码TcpClient的这个类有Connect方法,可以连接到Server端上,自己试试。
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MyTcpListener
{
public static void Main()
{
TcpListener server = null;
try
{
Int32 port = 13000;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
server = new TcpListener(localAddr, port);
server.Start();
Byte[] bytes = new Byte[256];
String data = null;
while (true)
{
Console.Write("Waiting for a connection... ");
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");