C#网络通信
Server:
using System.Net;
using System.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ServerConsole
{
class Server
{
static void Main(string[] args)
{
Console.WriteLine("Server is runing...");
IPAddress ip = new IPAddress(new byte[]{,,,});
TcpListener listener = new TcpListener(ip, ); listener.Start();//开始侦听
while (true)
{
//获取一个连接,中断方法
TcpClient remoteClient = listener.AcceptTcpClient();
//打印连接客户端的信息
Console.WriteLine("Client Connected!{0}---->{1}", remoteClient.Client.LocalEndPoint,remoteClient.Client.RemoteEndPoint);
}
}
}
}
Client:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets; namespace ClientConsole
{
class Client
{
static void Main(string[] args)
{
Console.WriteLine("Client is running...");
TcpClient client = null; for (int i = ; i < ; i++)
{
client = new TcpClient();
try
{
//与服务器建立连接
client.Connect("localhost", ); ;
}
catch (Exception ex)
{
Console.WriteLine("Exception occured.." + ex.Message);
return;
} //输出已连接到服务器
Console.WriteLine("Server Connected!{0}-->{1}",
client.Client.LocalEndPoint, client.Client.RemoteEndPoint);
}
ConsoleKey key;
do
{
key = Console.ReadKey(true).Key;
} while (key != ConsoleKey.Q);
}
}
}
C#网络通信的更多相关文章
- ZeroMQ实例-使用ZMQ(ZeroMQ)进行局域网内网络通信
本文内容摘要:1)安装zeromq.2)实例说明使用zmq进行网络间的消息发送和接收 首先在机器中安装zmq库 步骤如下: 1)下载zeromq的源代码,ZeroMQ的官方网址:http://zero ...
- 基础笔记12(socket,url网络通信)
进一步深入socket 1.网络通信条件: .IP地址,可用主机名. .传输数据时将不用的应用程序通过数字标识区分开来,这种标识称为逻辑端口,也称端口.(0-65535端口,一般系统预留0-1024) ...
- Windows Store App 网络通信 HttpWebRequest
如果希望更好地控制HTTP请求,可以使用System.Net类库中的HttpWebRequest类,该类对HTTP协议进行了完整的封装,并且提供了很多对HTTP协议中的 Header.Content和 ...
- socket网络通信
1.socket通常也称作"套接字",用于描述IP地址和端口.在internet上的主机一般运行了多个服务软件,同时提供几种服务,每种服务都打开一个socket,并绑定到一个端口上 ...
- 20145316&20145229实验五:网络通信
20145316&20145229实验五:网络通信 结对伙伴:20145316 博客链接:http://www.cnblogs.com/xxy745214935/p/6130897.html
- 网络通信之Socket与LocalSocket的比较
Socket与LocalSocket都可以实现网络通信,两个有什么区别呢? LocalSocket其通信方式与Socket差不多,只是LocalSocket没有跨越网络边界. 于是,思考到一个问题:a ...
- Android 网络通信API的选择和实现实例
Android开发网络通信一开始的时候使用的是AsyncTask封装HttpClient,没有使用原生的HttpURLConnection就跳到了Volley,随着OkHttp的流行又开始迁移到OkH ...
- java 25 - 2 网络编程之 网络通信三要素
网络通信三要素 IP地址: InetAddress 网络中设备的标识,不易记忆,可用主机名(计算机的标识号) 端口号: 用于标识进程的逻辑地址,不同进程的标识(正在运行的软件的标识号) 传输协议: 通 ...
- TCP/UDP,SOCKET网络通信,C++/Java实现
趁这两天没事干,就把网络通信这一块搞一搞,C/S方面的了解一下,很重要! TCP Server/Client
- Java网络通信初步认知
本文转载自:http://wing011203.cnblogs.com/ 在这篇文章里,我们主要讨论如何使用Java实现网络通信,包括TCP通信.UDP通信.多播以及NIO. TCP连接 TCP的基础 ...
随机推荐
- Helpers\FastCache
Helpers\FastCache phpFastCache is a high-performance, distributed object caching system, generic in ...
- zlib导致Ubuntu登录管理器失效
ubuntu版本:10.04 现象:开机之后无法启动登录管理器. 原因:zlib与登录管理器冲突. 解决:卸载zlib.
- Mysql 复习
1.my.ini :mysql 配置文件 [client]#password = your_passwordport = 3306socket = /tmp/mysq ...
- IOS下视频监控项目总结
一.项目说明 二.技术点 1.数据缓存 2.storyboard的使用 3.h264码流数据的解码 4.UDP通讯 三.解决方案 四.总结 五.相关资料
- 微信小程序(原名微信应用号)开发工具0.9版安装教程
微信小程序全称微信公众平台·小程序,原名微信公众平台·应用号(简称微信应用号) 声明 微信小程序开发工具类似于一个轻量级的IDE集成开发环境,目前仅开放给了少部分受微信官方邀请的人士(据说仅200个名 ...
- Font Awesome图标字体库(2015年05月25日)
Font Awesome是一款非常棒的字体图标工具,给个地址,具体的自已慢慢去体会,只能帮你到这儿了...... http://fortawesome.github.io/Font-Awesome/ ...
- Git CMD - remote: Manage set of tracked repositories
命令格式 git remote [-v | --verbose] git remote add [-t <branch>] [-m <master>] [-f] [--[no- ...
- 运用NPOI操作EXCEL
一.引入NPOI程序集 下载地址:http://pan.baidu.com/s/1qWI3Vgo 二.运用NPOI导出成excel文件 protected void btnOutExcel_Click ...
- Android之帧动画
MySurfaceView类: package com.fm; import android.content.Context; import android.graphics.Bitmap; impo ...
- .NET中开源CMS目录
提起开源cms,大家第一想到的是php的cms,因为php开源的最早,也最为用户和站长们认可,随着各大cms系统的功能的不断完善和各式各样的开源cms的出现,.net和java的高端的cms系统也逐渐 ...