随笔分类 - socket
摘要:对穿越NAT做些总结:先做个约定:内网A中有:A1(192.168.0.8)、A2(192.168.0.9)两用户,网关X1(一个NAT设备)有公网IP1.2.3.4内网B中有:B1(192.168.1.8)、B2(192.168.1.9)两用户,网关Y1(一个NAT设备)有公网IP1.2.3.5公网服务器:C (6.7.8.9)D (6.7.8.10)NAT两大类:lNAT(NetworkAddressTranslators):称为基本的NAT在客户机时192.168.0.8:4000——6.7.8.9:8000在网关时1.2.3.4:4000——6.7.8.9:8000服务器C6.7.8.
阅读全文
摘要:using System;using System.Collections.Generic;using System.Text;using System.Net.Sockets;using System.Net;using System.Threading;using System.Runtime.InteropServices;namespace ConsoleApplication2{ class Program { static Socket m_sListen; static void Main(string[] args) { ...
阅读全文
摘要:服务端和客户是通过这样一个结构体进行通信的using System;using System.IO;using System.Runtime.InteropServices;namespace AUS.Common{ /// <summary> /// 通信结构体 /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct Packet { public cmd cmd; public int len;...
阅读全文
摘要:SocketAsyncEventArgs 连接池SocketAsyncEventArgsPoolusing System;using System.Net.Sockets;using System.Collections.Generic;namespace LinFx.Net.Sockets{ class SocketAsyncEventArgsPool { private readonly Stack<SocketAsyncEventArgs> m_pool; private readonly object syncLocker = new object(); public So
阅读全文
摘要:using System;using System.Collections.Generic;using System.IO;using System.Net;using System.Net.Sockets;using System.Threading;using LinFx.Net;using LinFx.Win32;namespace LinFx.Net.Server{ /// <summary> /// 异步I/O模型 /// </summary> public class IOCPServer : IDisposable { private IntPtr m_h
阅读全文
摘要:今天我们来学 socket 发送结构体1. 先看要发送的结构体代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Runtime.InteropServices;namespaceLin.p2p.Mo{///<summary>///通信消息格式///</summary>[Se
阅读全文
摘要:今天来写一个UPD1.服务端:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Net.Sockets;usingSystem.Net;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){//1.创建套节字S
阅读全文
摘要:现在来传一个图片看看, 改改程序, 看看服务端图片为 140K, 1.jgp1. 服务端代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Text;4usingSystem.Net.Sockets;5usingSystem.Net;6usingSystem.IO;78namespaceConsoleApplication19
阅读全文
摘要:1. 服务端程序Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Text;4usingSystem.Net.Sockets;5usingSystem.Net;67namespaceConsoleApplication18{9classProgram10{11staticvoidMain(string[]args)12{13//
阅读全文
摘要:最近在用C#做一个项目的时候,Socket发送消息的时候遇到了服务端需要接收C++结构体的二进制数据流,这个时候就需要用C#仿照C++的结构体做出一个结构来,然后将其转换成二进制流进行发送,之后将响应消息的二进制数据流转换成C#结构。1、仿照C++结构体写出C#的结构来 using System.Runtime.InteropServices; [Serializable] // 指示可序列化 [StructLayout(LayoutKind.Sequential, Pack = 1)] // 按1字节对齐 public struct Operator { public ushort id;
阅读全文