visual c# 网络编程技术与实践实例包括几个源码

源代码在线查看: program.cs

软件大小: 1019 K
上传用户: Mrsliu
关键词: visual 网络 编程技术 实践
下载地址: 免注册下载 普通下载 VIP

相关代码

				using System;
				using System.Collections.Generic;
				using System.Text;
				using System.Net;
				using System.Net.Sockets;
				
				
				namespace socketclient
				{
				    class Program
				    {
				        static void Main(string[] args)
				        {
				            Socket Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); //建立客户端套接字
				            IPAddress adr = IPAddress.Parse("127.0.0.1");
				            IPEndPoint ep = new IPEndPoint(adr, 3000);
				
				            Server.Connect(ep); //完成绑定
				
				            byte[] buffer = new byte[255];
				            String data = null;
				            int recv = 0;
				            recv = Server.Receive(buffer);
				
				            if (recv > 0)
				            {
				                Console.WriteLine("连接上...");
				                Console.WriteLine("从服务器接收数据...");
				
				                data = Encoding.ASCII.GetString(buffer, 0, recv);
				                Console.WriteLine(data);
				                while (true)
				                {
				                    String input;
				                    input = Console.ReadLine();
				                    if (input == "exit")
				                    {
				                        break;
				                    }
				                    Server.Send(Encoding.ASCII.GetBytes(input));
				                }
				
				                Console.WriteLine("连接断开...");
				                Server.Shutdown(SocketShutdown.Both);
				                Server.Close();
				            }
				
				        }
				    }
				}
							

相关资源