Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
client.cs
Package: Visual.rar [view]
Upload User: yiyuerguo
Upload Date: 2014-09-27
Package Size: 3781k
Code Size: 1k
Category:
CSharp
Development Platform:
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();
- }
- }