本文介绍了编辑在线游戏服务器套接字[创建客户端]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hello Codeone上的所有人,标题说我正在编辑一个在线游戏服务器套接字来为同一个游戏但是作为一个客户端套接字,实际上我尝试了很多次却失败了,花了更多的时间在那个上,好吧,这是我的想法.. 服务器和客户端每个都有2个插座...登录插座,游戏插座 服务器套接字工作得很好,但我需要编辑它以与客户端一起工作,只接收和发送数据,字节和数据包..并且不要监听传入的连接...正如我所说我花了很长时间在这个时间我得到它成功,但不是因为我正在寻找...... i希望它在服务器套接字的同时发送和接收...... 这里是套接字文件... 那么可以在这些文件中进行哪些编辑来制作正如我解释的那样? public class WinSocke t { 私人套接字连接; private bool disconnected = false ; public bool 已禁用= false ; public WinSocket() { Connection = new Socket( AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); } public WinSocket(套接字套接字) { Connection = socket; } public void Bind(EndPoint point) { if (已断开连接) return ; Connection.Bind(point); } public void 收听( int 积压) { 如果(已断开连接)返回 ; Connection.Listen(backlog); } public void BeginAccept(AsyncCallback async , object state) { if (已禁用) return ; 尝试 { 如果(已断开连接)返回; Connection.BeginAccept( async ,state); } catch {已停用= true ; } } public void BeginReceive( byte [] buffer, int offset, int size,SocketFlags flag,AsyncCallback回调,对象状态) { 如果(已禁用) return ; 尝试 { 如果(已断开连接||!已连接) 返回; Connection.BeginReceive(缓冲区,偏移量,大小,标志,回调,状态); } catch {已停用= true ; } } public int EndReceive(IAsyncResult res, out SocketError错误) { err = SocketError.Disconnecting; if (已禁用) return 0 ; 尝试 { 如果(!可用)返回 0 ; return Connection.EndReceive(res, out err); } catch {已停用= true ; } return 0 ; } public 套接字EndAccept(IAsyncResult async ) { if (已禁用) return null ; 尝试 { 如果(已断开连接) return null ; return Connection.EndAccept( async ); } catch {已停用= true ; } 返回 null ; } public 套接字接受() { 如果(已禁用) return null ; 尝试 { 如果(已断开连接) return null ; return Connection.Accept(); } catch {已停用= true ; } 返回 null ; } public void 关闭() { // Connection.Close(); } public void 发​​送( byte [] buffer) { 如果(已禁用) return ; 尝试 { 如果(已断开连接)返回; Connection.Send(buffer); } catch {已停用= true ; } } public void 断开连接( bool 重用) { if (已禁用)返回; 尝试 { 如果(!已断开连接) disconnected = true ; else return ; Connection.Disconnect(重用); } catch {已停用= true ; } } public void 关机(SocketShutdown类型) { // Connection.Shutdown(type); } public bool 已关闭 { get { if (已禁用) return false ; 尝试 { 如果(已断开连接)返回 false ; return Connection.Connected; } catch {已停用= true ; } 返回 false ; } } public int Receive( byte [] buffer) { if (已断开连接)返回 0 ; return Connection.Receive(buffer); } public EndPoint RemoteEndPoint { get { 如果(已禁用) return new IPEndPoint( 1 , 1 ); 尝试 { return Connection.RemoteEndPoint; } catch {已停用= true ; } 返回 新 IPEndPoint( 1 , 1 ); } } 私人 bool 可用 { get { return !disconnected; } } public void 禁用() { 尝试 {已停用= true ; Connection.Close(); } catch {已停用= true ; } } } public class SyncSocketWrapper:Interfaces.ISocketWrapper { public int BufferSize { get ; set ; } public byte [] Buffer { get ; set ; } public WinSocket Socket { get ; set ; } public object 连接器 { get ; set ; } public Interfaces.ISocketWrapper Create(套接字套接字) { BufferSize = 8000 ; Socket = new WinSocket(socket); Buffer = new byte [BufferSize]; 返回 此; } private 线程线程; 私有 SyncSocket服务器; public void BeginReceive(SyncSocket服务器) {服务器=服务器; thread = new 线程( new ThreadStart(Receive)); thread.Start(); } private void Receive() { 尝试 { ,而(Socket.Connected) { 尝试 { int RecvSize = Socket .Receive(缓冲液); if (RecvSize > 0 ) { byte [] buffer = new 字节 [RecvSize]; for ( int i = 0 ; i < RecvSize; i ++) { buffer [i] = Buffer [i]; } Server.InvokeOnClientReceive( this ,buffer); } else { Server.InvokeDisconnect( this ); return ; } } catch (SocketException) { Server.InvokeDisconnect(此); return ; } catch (ObjectDisposedException) { Server.InvokeDisconnect(此); return ; } catch (例外e){MessageBox.Show(e.Message); } } Server.InvokeDisconnect( this ); return ; } catch (ThreadAbortException) { Server.InvokeDisconnect(此); return ; } } } public class SyncSocket { private WinSocket Connection = new WinSocket(); 私人 bool 已启用; public event 操作< Interfaces.ISocketWrapper> OnClientConnect; public event 操作< Interfaces.ISocketWrapper> OnClientDisconnect; public event Action< byte [],Interfaces.ISocketWrapper> OnClientReceive; private ushort port; private 线程mainThread; public SyncSocket( ushort port) { if (!this.enabled) { this .port = port ; this .Connection.Bind( new IPEndPoint(IPAddress.Any,此 .port)); this .Connection.Listen( 10 ); 此 .enabled = true ; mainThread = new 线程( new ThreadStart(此 .SyncConnect)); mainThread.Start(); } } 私有 void SyncConnect( ) { 尝试 { while ( true ) { if (Connection.Disabled) return ; if (!this.enabled) return ; SyncSocketWrapper sender = null ; 尝试 { sender = new SyncSocketWrapper(); sender.Create( this .Connection.Accept()); if ( this .OnClientConnect!= null ) { this .OnClientConnect(sender); } sender.BeginReceive( this ); } catch (SocketException e) { MessageBox.Show(e.Message); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } catch (例外e){MessageBox.Show(e.Message); } } } catch (ThreadAbortException e) { MessageBox.Show(e.Message) ); } } public void InvokeOnClientConnect( SyncSocketWrapper发送者) { if ( this .OnClientConnect!= null ) { this .OnClientConnect(sender); } } public void InvokeOnClientReceive( SyncSocketWrapper sender, byte [] buffer) { if ( this .OnClientReceive!= null ) { this .OnClientReceive(buffer,sender); } } public void 禁用( ) { if ( this .enabled) { this .Connection.Disable(); 此 .enabled = false ; } } public void 启用( ) { if (!this.enabled) { 此 .Connection.Bind( new IPEndPoint(IPAddress.Any, this .port)) ; this .Connection.Listen( 100 ); 此 .enabled = true ; if (mainThread!= null ) { mainThread。中止(); mainThread = null ; } mainThread = new 线程( new ThreadStart(此 .SyncConnect)); mainThread.Start(); } } 私有 void enabledCheck( string 变量) { if ( this .enabled) { throw new 异常( 无法修改 +变量+ 启用套接字时。); } } public void InvokeDisconnect( SyncSocketWrapper Client) { if (Client!= null ) { try { if (Client.Socket。已连接) { Client.Socket.Disconnect( false ); Client.Socket.Shutdown(SocketShutdown.Both); Client.Socket.Close(); if ( this .OnClientDisconnect!= null ) this .OnClientDisconnect(Client); Client.Connector = null ; Client = null ; } else { Client.Socket.Shutdown(SocketShutdown.Both); Client.Socket.Close(); if ( this .OnClientDisconnect!= null ) this .OnClientDisconnect(Client); Client.Connector = null ; Client = null ; } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message) ; } } } public bool 已启用 { 获取 { 返回 此 .enabled; } } public ushort Port { get { return 此 .port; } 设置 { 此 .enabledCheck ( Port); 此 .port = value ; } } } public class AsyncSocketWrapper:Interfaces.ISocketWrapper { public int BufferSize { 获得; set ; } public byte [] Buffer { get ; set ; } public WinSocket Socket { get ; set ; } public object 连接器 { get ; set ; } public Interfaces.ISocketWrapper Create(套接字套接字) { BufferSize = 8000 ; Socket = new WinSocket(socket); Buffer = new byte [BufferSize]; 返回 此; } } public class AsyncSocket { private int backlog; private int clientbuffersize = 0xffff; private WinSocket Connection = new WinSocket(); 私人 bool 已启用; public bool GameServer = false ; public event 操作< Interfaces.ISocketWrapper> OnClientConnect; public event 操作< Interfaces.ISocketWrapper> OnClientDisconnect; public event Action< byte [],Interfaces.ISocketWrapper> OnClientReceive; private ushort port; public AsyncSocket( ushort port) { if (!this.enabled) { this .port = port ; this .Connection.Bind( new IPEndPoint(IPAddress.Any,此 .port)); this .Connection.Listen( 100 ); this .Connection.BeginAccept( new AsyncCallback( this .AsyncConnect), null ); 此 .enabled = true ; } } 私有 void AsyncConnect( IAsyncResult res) { AsyncSocketWrapper sender = null ; 尝试 { sender = new AsyncSocketWrapper(); sender.Create(this.Connection.EndAccept(res)); if (sender.Socket == null) { this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); return ; } if (this.OnClientConnect != null) { this.OnClientConnect(sender); } sender.Socket.BeginReceive(sender.Buffer, 0, sender.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), sender); this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); } catch (SocketException e) { MessageBox.Show(e.Message); if (this.enabled) { this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } } private unsafe void AsyncReceive(IAsyncResult res) { bool was = false; try { SocketError error; AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState; int RecvSize = asyncState.Socket.EndReceive(res, out error); if ((error == SocketError.Success) && (RecvSize > 0)) { was = true; byte[] buffer = new byte[RecvSize]; for (int i = 0; i < RecvSize; i++) { buffer[i] = asyncState.Buffer[i]; } if (this.OnClientReceive != null) { this.OnClientReceive(buffer, asyncState); } asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState); } else { this.InvokeDisconnect(asyncState); } } catch (SocketException e) { MessageBox.Show(e.Message); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } catch (Exception e) { MessageBox.Show(e.Message); if (was) { AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState; asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState); } } } public void Disable() { if (this.enabled) { this.Connection.Disable(); this.enabled = false; } } public void Enable() { if (!this.enabled) { this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port)); this.Connection.Listen(this.backlog); this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); this.enabled = true; } } private void enabledCheck(string Variable) { if (this.enabled) { throw new Exception(\"Cannot modify \" + Variable + \" while socket is enabled.\"); } } public void InvokeDisconnect(AsyncSocketWrapper Client) { if (Client != null) { try { if (Client.Socket.Connected) { Client.Socket.Shutdown(SocketShutdown.Both); Client.Socket.Close(); if (this.OnClientDisconnect != null) { this.OnClientDisconnect(Client); } Client.Connector = null; Client = null; } else { if (this.OnClientDisconnect != null) { this.OnClientDisconnect(Client); } Client.Connector = null; Client = null; } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } } } public int Backlog { get { return this.backlog; } set { this.enabledCheck(\"Backlog\"); this.backlog = value; } } public int ClientBufferSize { get { return this.clientbuffersize; } set { this.enabledCheck(\"ClientBufferSize\"); this.clientbuffersize = value; } } public bool Enabled { get { return this.enabled; } } public ushort Port { get { return this.port; } set { this.enabledCheck(\"Port\"); this.port = value; } } } public interface ISocketWrapper { int BufferSize { get; set ; } byte[] Buffer { get; set ; } WinSocket Socket { get; set ; } object Connector { get; set ; } ISocketWrapper Create(System.Net.Sockets.Socket socket); } 解决方案 I think you should have a look at this: Reusable multithreaded TCP client and server classes with example project in VB.NET[^] That will do what you need - two way conversations, appearing to be simultaneous. You won’t need a separate socket to log in either. Yes, it’s a VB.NET project, but the tcp/ip classes are wrapped in a .dll, so you’ll just need to add a reference to it in your project. -PeteHello Everyone at CodeProject , as title say i am editing an Online Game Server Socket to make it for the same game but as a client socket , actually i tried it many times but fails , spent more time on that , well ,, here is my idea..Server and client each one have 2 sockets... Login Socket , Game SocketServer socket working very well , but i need to edit it to work with the client , just receiving and sending data , bytes and packets.. and don`t listen for incoming connections ... as i said i spent long time on this i got it worked successfully , but not as i am looking for ...i want it sending and receiving at same time as Server Socket doing ...here is Socket Files ...So what edits can be done in this files to make it as i explained ?public class WinSocket { private Socket Connection; private bool disconnected = false; public bool Disabled = false; public WinSocket() { Connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } public WinSocket(Socket socket) { Connection = socket; } public void Bind(EndPoint point) { if (disconnected) return; Connection.Bind(point); } public void Listen(int backlog) { if (disconnected) return; Connection.Listen(backlog); } public void BeginAccept(AsyncCallback async, object state) { if (Disabled) return; try { if (disconnected) return; Connection.BeginAccept(async, state); } catch { Disabled = true; } } public void BeginReceive(byte[] buffer, int offset, int size, SocketFlags flag, AsyncCallback callback, object state) { if (Disabled) return; try { if (disconnected || !Connected) return; Connection.BeginReceive(buffer, offset, size, flag, callback, state); } catch { Disabled = true; } } public int EndReceive(IAsyncResult res, out SocketError err) { err = SocketError.Disconnecting; if (Disabled) return 0; try { if (!Usable) return 0; return Connection.EndReceive(res, out err); } catch { Disabled = true; } return 0; } public Socket EndAccept(IAsyncResult async) { if (Disabled) return null; try { if (disconnected) return null; return Connection.EndAccept(async); } catch { Disabled = true; } return null; } public Socket Accept() { if (Disabled) return null; try { if (disconnected) return null; return Connection.Accept(); } catch { Disabled = true; } return null; } public void Close() { //Connection.Close(); } public void Send(byte[] buffer) { if (Disabled) return; try { if (disconnected) return; Connection.Send(buffer); } catch { Disabled = true; } } public void Disconnect(bool reuse) { if (Disabled) return; try { if (!disconnected) disconnected = true; else return; Connection.Disconnect(reuse); } catch { Disabled = true; } } public void Shutdown(SocketShutdown type) { //Connection.Shutdown(type); } public bool Connected { get { if (Disabled) return false; try { if (disconnected) return false; return Connection.Connected; } catch { Disabled = true; } return false; } } public int Receive(byte[] buffer) { if (disconnected) return 0; return Connection.Receive(buffer); } public EndPoint RemoteEndPoint { get { if (Disabled) return new IPEndPoint(1, 1); try { return Connection.RemoteEndPoint; } catch { Disabled = true; } return new IPEndPoint(1, 1); } } private bool Usable { get { return !disconnected; } } public void Disable() { try { Disabled = true; Connection.Close(); } catch { Disabled = true; } } }public class SyncSocketWrapper : Interfaces.ISocketWrapper { public int BufferSize { get; set; } public byte[] Buffer { get; set; } public WinSocket Socket { get; set; } public object Connector { get; set; } public Interfaces.ISocketWrapper Create(Socket socket) { BufferSize = 8000; Socket = new WinSocket(socket); Buffer = new byte[BufferSize]; return this; } private Thread thread; private SyncSocket Server; public void BeginReceive(SyncSocket server) { Server = server; thread = new Thread(new ThreadStart(Receive)); thread.Start(); } private void Receive() { try { while (Socket.Connected) { try { int RecvSize = Socket.Receive(Buffer); if (RecvSize > 0) { byte[] buffer = new byte[RecvSize]; for (int i = 0; i < RecvSize; i++) { buffer[i] = Buffer[i]; } Server.InvokeOnClientReceive(this, buffer); } else { Server.InvokeDisconnect(this); return; } } catch (SocketException) { Server.InvokeDisconnect(this); return; } catch (ObjectDisposedException) { Server.InvokeDisconnect(this); return; } catch (Exception e) { MessageBox.Show(e.Message); } } Server.InvokeDisconnect(this); return; } catch (ThreadAbortException) { Server.InvokeDisconnect(this); return; } } }public class SyncSocket { private WinSocket Connection = new WinSocket(); private bool enabled; public event Action<Interfaces.ISocketWrapper> OnClientConnect; public event Action<Interfaces.ISocketWrapper> OnClientDisconnect; public event Action<byte[], Interfaces.ISocketWrapper> OnClientReceive; private ushort port; private Thread mainThread; public SyncSocket(ushort port) { if (!this.enabled) { this.port = port; this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port)); this.Connection.Listen(10); this.enabled = true; mainThread = new Thread(new ThreadStart(this.SyncConnect)); mainThread.Start(); } } private void SyncConnect() { try { while (true) { if (Connection.Disabled) return; if (!this.enabled) return; SyncSocketWrapper sender = null; try { sender = new SyncSocketWrapper(); sender.Create(this.Connection.Accept()); if (this.OnClientConnect != null) { this.OnClientConnect(sender); } sender.BeginReceive(this); } catch (SocketException e) { MessageBox.Show(e.Message); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } catch (Exception e) { MessageBox.Show(e.Message); } } } catch (ThreadAbortException e) { MessageBox.Show(e.Message); } } public void InvokeOnClientConnect(SyncSocketWrapper sender) { if (this.OnClientConnect != null) { this.OnClientConnect(sender); } } public void InvokeOnClientReceive(SyncSocketWrapper sender, byte[] buffer) { if (this.OnClientReceive != null) { this.OnClientReceive(buffer, sender); } } public void Disable() { if (this.enabled) { this.Connection.Disable(); this.enabled = false; } } public void Enable() { if (!this.enabled) { this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port)); this.Connection.Listen(100); this.enabled = true; if (mainThread != null) { mainThread.Abort(); mainThread = null; } mainThread = new Thread(new ThreadStart(this.SyncConnect)); mainThread.Start(); } } private void enabledCheck(string Variable) { if (this.enabled) { throw new Exception("Cannot modify " + Variable + " while socket is enabled."); } } public void InvokeDisconnect(SyncSocketWrapper Client) { if (Client != null) { try { if (Client.Socket.Connected) { Client.Socket.Disconnect(false); Client.Socket.Shutdown(SocketShutdown.Both); Client.Socket.Close(); if (this.OnClientDisconnect != null) this.OnClientDisconnect(Client); Client.Connector = null; Client = null; } else { Client.Socket.Shutdown(SocketShutdown.Both); Client.Socket.Close(); if (this.OnClientDisconnect != null) this.OnClientDisconnect(Client); Client.Connector = null; Client = null; } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } } } public bool Enabled { get { return this.enabled; } } public ushort Port { get { return this.port; } set { this.enabledCheck("Port"); this.port = value; } } }public class AsyncSocketWrapper : Interfaces.ISocketWrapper { public int BufferSize { get; set; } public byte[] Buffer { get; set; } public WinSocket Socket { get; set; } public object Connector { get; set; } public Interfaces.ISocketWrapper Create(Socket socket) { BufferSize = 8000; Socket = new WinSocket(socket); Buffer = new byte[BufferSize]; return this; } }public class AsyncSocket { private int backlog; private int clientbuffersize = 0xffff; private WinSocket Connection = new WinSocket(); private bool enabled; public bool GameServer = false; public event Action<Interfaces.ISocketWrapper> OnClientConnect; public event Action<Interfaces.ISocketWrapper> OnClientDisconnect; public event Action<byte[], Interfaces.ISocketWrapper> OnClientReceive; private ushort port; public AsyncSocket(ushort port) { if (!this.enabled) { this.port = port; this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port)); this.Connection.Listen(100); this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); this.enabled = true; } } private void AsyncConnect(IAsyncResult res) { AsyncSocketWrapper sender = null; try { sender = new AsyncSocketWrapper(); sender.Create(this.Connection.EndAccept(res)); if (sender.Socket == null) { this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); return; } if (this.OnClientConnect != null) { this.OnClientConnect(sender); } sender.Socket.BeginReceive(sender.Buffer, 0, sender.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), sender); this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); } catch (SocketException e) { MessageBox.Show(e.Message); if (this.enabled) { this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } } private unsafe void AsyncReceive(IAsyncResult res) { bool was = false; try { SocketError error; AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState; int RecvSize = asyncState.Socket.EndReceive(res, out error); if ((error == SocketError.Success) && (RecvSize > 0)) { was = true; byte[] buffer = new byte[RecvSize]; for (int i = 0; i < RecvSize; i++) { buffer[i] = asyncState.Buffer[i]; } if (this.OnClientReceive != null) { this.OnClientReceive(buffer, asyncState); } asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState); } else { this.InvokeDisconnect(asyncState); } } catch (SocketException e) { MessageBox.Show(e.Message); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } catch (Exception e) { MessageBox.Show(e.Message); if (was) { AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState; asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState); } } } public void Disable() { if (this.enabled) { this.Connection.Disable(); this.enabled = false; } } public void Enable() { if (!this.enabled) { this.Connection.Bind(new IPEndPoint(IPAddress.Any, this.port)); this.Connection.Listen(this.backlog); this.Connection.BeginAccept(new AsyncCallback(this.AsyncConnect), null); this.enabled = true; } } private void enabledCheck(string Variable) { if (this.enabled) { throw new Exception("Cannot modify " + Variable + " while socket is enabled."); } } public void InvokeDisconnect(AsyncSocketWrapper Client) { if (Client != null) { try { if (Client.Socket.Connected) { Client.Socket.Shutdown(SocketShutdown.Both); Client.Socket.Close(); if (this.OnClientDisconnect != null) { this.OnClientDisconnect(Client); } Client.Connector = null; Client = null; } else { if (this.OnClientDisconnect != null) { this.OnClientDisconnect(Client); } Client.Connector = null; Client = null; } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); } } } public int Backlog { get { return this.backlog; } set { this.enabledCheck("Backlog"); this.backlog = value; } } public int ClientBufferSize { get { return this.clientbuffersize; } set { this.enabledCheck("ClientBufferSize"); this.clientbuffersize = value; } } public bool Enabled { get { return this.enabled; } } public ushort Port { get { return this.port; } set { this.enabledCheck("Port"); this.port = value; } } }public interface ISocketWrapper { int BufferSize { get; set; } byte[] Buffer { get; set; } WinSocket Socket { get; set; } object Connector { get; set; } ISocketWrapper Create(System.Net.Sockets.Socket socket); } 解决方案 I think you should have a look at this:Reusable multithreaded TCP client and server classes with example project in VB.NET[^]That will do what you need - two way conversations, appearing to be simultaneous. You won't need a separate socket to log in either.Yes, it's a VB.NET project, but the tcp/ip classes are wrapped in a .dll, so you'll just need to add a reference to it in your project.-Pete 这篇关于编辑在线游戏服务器套接字[创建客户端]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-26 08:21