- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
client.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Net.Sockets;
- public class client
- {
- public static void Main()
- {
- try
- {
- // 新建客户端套接字
- TcpClient tcpclnt = new TcpClient();
- Console.WriteLine("连接.....");
- // 连接服务器
- tcpclnt.Connect("127.0.0.1",8001);
- Console.WriteLine("已连接");
- Console.Write("请输入要传输的字符串 : ");
- // 读入字符串
- String str=Console.ReadLine();
- // 得到客户端的流
- Stream stm = tcpclnt.GetStream();
- // 发送字符串
- ASCIIEncoding asen= new ASCIIEncoding();
- byte[] ba=asen.GetBytes(str);
- Console.WriteLine("传输中.....");
- stm.Write(ba,0,ba.Length);
- // 接收从服务器返回的信息
- byte[] bb=new byte[100];
- int k=stm.Read(bb,0,100);
- // 输出服务器返回信息
- for (int i=0;i<k;i++)
- {
- Console.Write(Convert.ToChar(bb[i]));
- }
- // 关闭客户端连接
- tcpclnt.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine("Error..... " + e.StackTrace);
- }
- Console.ReadLine();
- }
- }