当前位置: 首页 > news >正文

怎么建设一个营销型网站手机软件开发和网站开发

怎么建设一个营销型网站,手机软件开发和网站开发,公司网站开发费用账务处理,用织梦做网站都需要用什么需要提前了解的Socket知识点#xff1a; Client端输入的IP都是Server所在电脑的IPServer最好设置0.0.0.0这样无论迁移到哪个电脑上#xff0c;都是那台电脑的IPClient和Server必须在同一个局域网之下#xff0c;否则不能通信#xff1b;如果要实现跨局域网通信#xff0c…需要提前了解的Socket知识点 Client端输入的IP都是Server所在电脑的IPServer最好设置0.0.0.0这样无论迁移到哪个电脑上都是那台电脑的IPClient和Server必须在同一个局域网之下否则不能通信如果要实现跨局域网通信需要使用公网IP通过阿里云等 整个聊天室的代码分为两个模块 Server服务器模块只能有一个用来存储监听用户发送的内容Client客户模块可以有多个各个用户直接进行收发信息 以下是Server代码 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks;namespace Server {class Program{static Socket socket null;static void Main(string[] args){socket new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);socket.Bind(new IPEndPoint(IPAddress.Parse(0.0.0.0), 60000));socket.Listen(10);Console.WriteLine(已启动侦听);Task.Run(Connect);Console.ReadLine();}static ListSocket socketPool new ListSocket();static Socket acceptSocket null;static void Connect(){while (true){try{acceptSocket socket.Accept();var receiveSocket acceptSocket;Console.WriteLine($已接受连接{receiveSocket.RemoteEndPoint});socketPool.Add(receiveSocket);Task.Run(Receive);}catch (Exception ex){Console.WriteLine($连接失败{ex.Message});}}}static void Receive(){var receiveSocket acceptSocket;while (true){if (receiveSocket null) continue;if (!receiveSocket.Connected) continue;try{byte[] buffer new byte[1024];var len receiveSocket.Receive(buffer);if (len 1) continue;var msg Encoding.UTF8.GetString(buffer, 0, len);Console.WriteLine($来自 {receiveSocket.RemoteEndPoint} 的消息 {msg});var responseBuffer Encoding.UTF8.GetBytes($来自{receiveSocket.RemoteEndPoint} 的消息{msg});// receiveSocket.Send(responseBuffer);//清理失效的连接for (int i socketPool.Count - 1; i 0; i--){if (socketPool[i] null || !socketPool[i].Connected){socketPool.RemoveAt(i);}}//广播消息除了发送消息方之外的全部广播foreach (var s in socketPool){if (s ! receiveSocket){s.Send(responseBuffer);}}buffer null;}catch (Exception ex){Console.WriteLine(ex.Message \n);}}}} }以下是Client代码 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;/// summary /// 客户端 /// /summary namespace WpfApp1 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{Socket socket null;public MainWindow(){InitializeComponent();btnConnect.Click btnConnect_Click;btnSend.Click btnSend_Click;Task.Run(Receive);}private void btnConnect_Click(object sender, RoutedEventArgs e){if (socket ! null socket.Connected){ShowMessage($无需重复连接);return;}try{socket new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);ShowMessage($LocalEndPoint{socket.LocalEndPoint},RemoteEndPoint{socket.RemoteEndPoint});var ipEndPoint new IPEndPoint(IPAddress.Parse(txtIP.Text), int.Parse(txtPort.Text));socket.Connect(ipEndPoint);if (socket.Connected){ShowMessage($成功连接到{socket.RemoteEndPoint});}}catch (Exception ex){ShowMessage($连接失败{ex.Message});socket null;}}private void btnSend_Click(object sender, RoutedEventArgs e){if (!socket.Connected){ShowMessage($未连接无法发送);return;}try{if (rtxtSend.Text ! ){var buffer Encoding.UTF8.GetBytes(rtxtSend.Text);socket.Send(buffer);ShowMessage($发送到{socket.RemoteEndPoint},消息{rtxtSend.Text});}rtxtSend.Text null;}catch (Exception ex){ShowMessage($发送失败{socket.RemoteEndPoint},{ex.Message});socket null;}}private void Receive(){while (true){if (socket null) continue;if (!socket.Connected) continue;try{byte[] buffer new byte[1024];if (buffer ! null){int len socket.Receive(buffer);if (len 1) continue;string msg Encoding.UTF8.GetString(buffer, 0, len);ShowMessage(msg);}buffer null;}catch (Exception ex){ShowMessage(ex.Message \n);socket null;}}}private void ShowMessage(string msg){///这是Winform的用法//子线程调用 //if (rtxtLog.InvokeRequired) //c#中禁止跨线程直接访问控件InvokeRequired是为了解决这个问题而产生的//{// rtxtLog.Invoke(new Action(() rtxtLog.Text msg \n));//}//主线程调用//else//{// rtxtLog.Text msg \n;//}if (!CheckAccess()) //WPF使用Dispatcher控制对消息泵的访问而不是让每个控件负责访问UI线程。{Dispatcher.Invoke(new Action(() rtxtLog.Text msg \n));}//主线程调用else{rtxtLog.Text msg \n;}}} }
http://www.pierceye.com/news/716750/

相关文章:

  • 雄安专业网站建设方案长沙做网站建设
  • 微信上的网站实物黄金哪个网站做的好
  • 网站建设的作用和用途wordpress外网固定链接
  • 网站做多长时间才有流量上海商城网站制作公司
  • 做电影网站服务器网站如何备案 流程图
  • 太原建站模板搭建wordpress attachment
  • 购买腾讯备案网站网站错误列表
  • 怎么查看网站的外链php网站建设流程图
  • 顺企网萍乡网站建设wordpress 读者墙
  • 电力建设期刊网站投稿域名提供商
  • 广东网站备案需要多久oa信息化管理系统平台
  • 哪个网站可以做担保交易小程序排行榜
  • 网站用html做的怎么弄后台中铁十六局个人门户网
  • 一个网站怎么做流量统计佛山市seo广告优化工具
  • 机关网站建设需求文档国家住建部官网
  • 一条龙网站建设哪家好六安招聘网官网
  • 网站建设 中企动力阀门和建设银行类似的网站
  • 所有做运动的网站姜堰网网站
  • 广西汽车网网站建设影楼微网站建设方案
  • 企业展厅设计比较好的公司北京优化服务
  • 网站的icp 备案信息wordpress爆破字典
  • 福建厦门网站建设公司网站代码素材建设
  • 广州网络公司建站e语言可以做网站吗
  • 不想用原来的网站模板了就用小偷工具采集了一个可是怎么替换seo顾问张智伟
  • 效果好的徐州网站开发建设网站怎么学
  • 上海网站设计要多少钱建设银行个人网站打不开
  • 哪个网站做欧洲旅行比较好东营网站制作
  • 做pc端网站效果wordpress js 添加图片
  • 给装修公司做网站商标设计大全
  • 深圳做网站公司有哪些地方国际形势最新消息