internal void method_5(SocketInformation socketInformation_0, int int_0) { SocketConnection Message = new SocketConnection(Convert.ToUInt32(int_0), socketInformation_0); this.Message1_0[int_0] = Message; Essential.GetGame().GetClientManager().AddClient((uint)int_0, ref Message); }
internal static void TransferConnection(ClientManager clientManager, string cacheId, Alachisoft.NCache.Common.Protobuf.Command command, long ackowledgementId) { try { if (!CacheProvider.Provider.IsRunning(cacheId)) { throw new Exception("Specified cache is not running."); } int cacheProcessPID = CacheProvider.Provider.GetCacheInfo(cacheId).CacheProcessId; if (cacheProcessPID == 0) { cacheProcessPID = CacheProvider.Provider.GetProcessID(cacheId); } clientManager.IsDisposed = true; SocketInformation socketInfo = clientManager.ClientSocket.DuplicateAndClose(cacheProcessPID); socketInfo.Options |= SocketInformationOptions.UseOnlyOverlappedIO; byte[] commandByte = SerializeCommand(command); CacheProvider.Provider.TransferConnection(socketInfo, cacheId, commandByte); }catch (Exception ex) { throw; } }
public string readLine() { string toReturn = ""; while (toReturn.Replace(delimeter, "") == "") { toReturn = ""; for (int i = 0; i < clients.Count; i++) { SocketInformation client = null; lock (clients) { if (i >= clients.Count) { continue; } client = clients[i]; } client.WriteProect.WaitOne(); toReturn += client.lastRead + delimeter; client.WriteProect.ReleaseMutex(); } } return(toReturn); }
public bool Open(byte[] socketInformationBytes) { try { SocketInformation SI = new SocketInformation(); SI.ProtocolInformation = socketInformationBytes; SI.Options = new SocketInformationOptions(); SI.Options = SocketInformationOptions.Connected; _Socket = new Socket(SI); _Socket.Blocking = true; if (_Socket.Connected) { _Stream = new NetworkStream(_Socket); } return(_Socket.Connected); } catch (SocketException sex) { RMLog.Exception(sex, "SocketException in TcpConnection::Open(). ErrorCode=" + sex.ErrorCode.ToString()); return(false); } catch (Exception ex) { RMLog.Exception(ex, "Exception in TcpConnection::Open()"); return(false); } }
public SocketConnection(uint uint_1, SocketInformation socketInformation_0) : base(socketInformation_0) { this.uint_0 = uint_1; this.string_0 = base.RemoteEndPoint.ToString().Split(new char[] { ':' })[0]; }
public customSocket(SocketInformation sockInfo) : base(sockInfo) { _timer = new Timer { Interval = _interval }; _timer.Elapsed += TimerTick; }
public SocketConnection(uint pSockID, SocketInformation socketInformation_0) : base(socketInformation_0) { this.bool_0 = false; this.Id = pSockID; this.Address = base.RemoteEndPoint.ToString().Split(new char[] { ':' })[0]; }
public NexonSocket(SocketInformation socketInformation) : base(socketInformation) { header = new byte[3]; packet = new byte[32768]; headerLength = 3; mutexPacketSend = new Mutex(); }
public CustomSocket(SocketInformation socketInformation) : base(socketInformation) { timer = new Timer { Interval = INTERVAL }; timer.Tick += TimerTick; }
public AsynchronousSocket(SocketInformation socketInformation) { InitializeProperties(); socket = new Socket(socketInformation); //socket.LingerState = new LingerOption(false, 0); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); }
/* * 网络流事例 */ public void DataStream() { SocketInformation mySocketinfo = new SocketInformation(); Socket mySocket = new Socket(mySocketinfo); NetworkStream myNetStrem = new NetworkStream(mySocket); FileStream myFileStream = new FileStream("文件路径", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 255, true); //true 表示异步流 StreamReader myStreamRead = new StreamReader("C:\\Documents and Settings\\All Users\\桌面\\金山毒霸账号.txt"); StreamWriter myStreamWriter = new StreamWriter("C:\\Documents and Settings\\All Users\\桌面\\金山毒霸账号.txt", true, System.Text.Encoding.UTF8); //如果不存在就新建一个文本 true byte[] myByt = new byte[1024]; string text = "字符串"; byte[] myByte = System.Text.Encoding.UTF8.GetBytes(text); //字符转换成字节 text = System.Text.Encoding.ASCII.GetString(myByte); //字节转换成字符 int number = 0; //读取网络文本流 myNetStrem.Read(myByt, 0, myByt.Length); myNetStrem.Flush(); //读取文本流 text = myStreamRead.ReadToEnd(); myStreamRead.Close(); //写入文本流 myStreamWriter.Write(text); myStreamWriter.Close(); myStreamWriter.Dispose(); //将网络流写入到文件 while ((number = myNetStrem.Read(myByt, 0, myByt.Length)) > 0) { myFileStream.Write(myByt, 0, number); myFileStream.Flush(); } myFileStream.Close(); //读取文件并写入网络流中 myFileStream = new FileStream("文件路径", FileMode.OpenOrCreate, FileAccess.Read); while ((number = myFileStream.Read(myByt, 0, myByt.Length)) > 0) { myNetStrem.Write(myByt, 0, myByt.Length); myNetStrem.Flush(); myByt = new byte[1024]; } myFileStream.Close(); //文本转换成RichTextBox text = "AA\rBB\rCC\n"; RichTextBox rich = new RichTextBox(); rich.Text = text; rich.AppendText("追加文本,不会换行"); text = rich.Lines[0]; }
/// <summary> /// Runs a client, using a socket handle from DuplicateAndClose /// </summary> /// <param name="socketinfo">The socket handle.</param> /// <param name="remoteEndPoint">The remote endpoint.</param> /// <param name="logtaskid">The log task ID.</param> /// <param name="controller">The controller instance</param> private static void RunClient(SocketInformation socketinfo, EndPoint remoteEndPoint, string logtaskid, RunnerControl controller) { var client = new TcpClient() { Client = new Socket(socketinfo) }; RunClient(client, remoteEndPoint, logtaskid, controller); }
public MusConnection(SocketInformation socketInformation) : base(socketInformation) { _buffer = new byte[512]; _asyncOnReceive = OnReceive; WaitForData(); }
public void GetResponse(SocketInformation clientInfo, HttpRequest req) { Socket client = new Socket(clientInfo); foreach (byte[] bytes in toSend) { client.Send(bytes); } client.Close(); }
/// <summary> /// Handles a request /// </summary> /// <param name="socket">The socket handle.</param> /// <param name="remoteEndPoint">The remote endpoint.</param> /// <param name="logtaskid">The task ID to use.</param> public void HandleRequest(SocketInformation socket, EndPoint remoteEndPoint, string logtaskid) { try { m_handleRequest.Invoke(m_wrapped, new object[] { socket, remoteEndPoint, logtaskid }); } catch (Exception ex) { Program.DebugConsoleOutput("Failed to process request: {0}", ex); } }
public void SocketCtr_InvalidProtocolInformation_ThrowsArgumentException(int?protocolInfoLength) { SocketInformation invalidInfo = new SocketInformation(); if (protocolInfoLength != null) { invalidInfo.ProtocolInformation = new byte[protocolInfoLength.Value]; } Assert.Throws <ArgumentException>(() => new Socket(invalidInfo)); }
public void SendResponse(SocketInformation clientInfo, HttpRequest req) { Socket client = new Socket(clientInfo); LinkedList <byte[]> toSend = _AppController.GetResponse(client, req); foreach (byte[] bytes in toSend) { client.Send(bytes); } client.Close(); }
private static void SerializeSocketInfo(SocketInformation socketInfo) { using (MemoryStream ms = new MemoryStream()) { BinaryFormatter.Serialize(ms, socketInfo); byte[] stuff = ms.ToArray(); File.WriteAllBytes(SocketInfoFile, stuff); Console.WriteLine($"Saved SocketInformation to: {SocketInfoFile}"); } }
internal void HandleNewConnection(SocketInformation connectioninfo, int PreconnID) { TcpConnection connection = new TcpConnection(Convert.ToUInt32(PreconnID), connectioninfo); this.Connections[PreconnID] = connection; PhoenixEnvironment.GetGame().GetClientManager().CreateAndStartClient((uint)PreconnID, ref connection); if (PhoenixEnvironment.GetConfig().data["emu.messages.connections"] == "1") { Logging.WriteLine(string.Concat(new object[] { ">> Connection [", PreconnID, "] from [", connection.ipAddress, "]" })); } }
public void Send(Socket client) { try { SocketInformation si = client.DuplicateAndClose(Id); Console.WriteLine("将socket[{0}]发送到后端服务器{1}上", client.Handle, Id); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(_stream, si); } catch { } }
public SocketCommunicator(GameQueue masterQueue) { RequestShutdown = false; Queue = masterQueue; SocketInfo = new SocketInformation(); ipHost = Dns.GetHostEntry(Dns.GetHostName()); ipAddr = ipHost.AddressList[0]; localEndPoint = new IPEndPoint(ipAddr, 0); PrimarySocket = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); }
public RedisSocket(SocketInformation socketInformation, bool useSsl = false, LocalCertificateSelectionCallback sslCertificateSelection = null, RemoteCertificateValidationCallback sslCertificateValidation = null, Action <RedisSocket> onConnect = null, Action <RedisSocket> onDisconnect = null) { m_UseSsl = useSsl; m_OnConnect = onConnect; m_OnDisconnect = onDisconnect; m_SslCertificateSelection = sslCertificateSelection; m_SslCertificateValidation = sslCertificateValidation; m_Socket = new RedisNativeSocket(socketInformation); }
public void Properties_Roundtrip() { SocketInformation si = default(SocketInformation); Assert.Equal((SocketInformationOptions)0, si.Options); si.Options = SocketInformationOptions.Listening | SocketInformationOptions.NonBlocking; Assert.Equal(SocketInformationOptions.Listening | SocketInformationOptions.NonBlocking, si.Options); Assert.Null(si.ProtocolInformation); byte[] data = new byte[1]; si.ProtocolInformation = data; Assert.Same(data, si.ProtocolInformation); }
public void BlockingState_IsTransferred(bool blocking) { using Socket original = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { Blocking = blocking }; Assert.Equal(blocking, original.Blocking); SocketInformation info = original.DuplicateAndClose(Environment.ProcessId); using Socket clone = new Socket(info); Assert.Equal(blocking, clone.Blocking); }
protected override DuplicateContext DuplicateConnection(ListenerSessionConnection session) { SocketInformation dupedSocket = default(SocketInformation); try { dupedSocket = (SocketInformation)session.Connection.DuplicateAndClose(this.ProcessId); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } // this normally happens if: // A) we don't have rights to duplicate handles to the WorkerProcess NativeErrorCode == 10022 // B) we fail to duplicate handle because the WorkerProcess is exiting/exited NativeErrorCode == 10024 // - in the self hosted case: report error to the client // - in the web hosted case: roundrobin to the next available WorkerProcess (if this WorkerProcess is down?) #if DEBUG if (exception is SocketException) { Debug.Print("TcpWorkerProcess.DuplicateConnection() failed duplicating socket for processId: " + this.ProcessId + " errorCode:" + ((SocketException)exception).NativeErrorCode + " exception:" + exception.Message); } #endif if (DiagnosticUtility.ShouldTraceError) { ListenerTraceUtility.TraceEvent(TraceEventType.Error, ListenerTraceCode.MessageQueueDuplicatedSocketError, SR.GetString(SR.TraceCodeMessageQueueDuplicatedSocketError), this, exception); } if (TD.MessageQueueDuplicatedSocketErrorIsEnabled()) { TD.MessageQueueDuplicatedSocketError(session.EventTraceActivity); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ServiceActivationException(SR.GetString(SR.MessageQueueDuplicatedSocketError), exception)); } if (DiagnosticUtility.ShouldTraceInformation) { ListenerTraceUtility.TraceEvent(TraceEventType.Information, ListenerTraceCode.MessageQueueDuplicatedSocket, SR.GetString(SR.TraceCodeMessageQueueDuplicatedSocket), this); } if (TD.MessageQueueDuplicatedSocketCompleteIsEnabled()) { TD.MessageQueueDuplicatedSocketComplete(session.EventTraceActivity); } return(new TcpDuplicateContext(dupedSocket, session.Via, session.Data)); }
public async Task RunAsync() { Console.WriteLine("********* HANDLER *********"); if (File.Exists(SocketInfoFile)) { File.Delete(SocketInfoFile); } while (true) { if (File.Exists(SocketInfoFile)) { SocketInformation socketInfo = DeserializeSocketInformation(); Console.WriteLine($"Found Socket info: {socketInfo.Options}"); Socket handler = new Socket(socketInfo); Console.WriteLine($"ESTABLISHED from SocketInformation: {handler.RemoteEndPoint} <------ {handler.LocalEndPoint}"); _bld.Clear(); while (true) { int count = await handler.ReceiveAsync(new ArraySegment <byte>(_buffer), SocketFlags.None); string part = Encoding.ASCII.GetString(_buffer, 0, count); _bld.Append(part); if (part.EndsWith(".")) { string recMsg = _bld.ToString().Substring(0, _bld.Length - 1); Console.WriteLine("RECEIVED:" + recMsg); if (recMsg.ToLower() == "exit") { break; } byte[] echo = Encoding.ASCII.GetBytes(recMsg + "!!!"); await handler.SendAsync(new ArraySegment <byte>(echo), SocketFlags.None); _bld.Clear(); } } handler.Shutdown(SocketShutdown.Both); handler.Close(); } Thread.Sleep(100); } }
private void recieveData() { while (true) { try { for (int i = 0; i < clients.Count; i++) { SocketInformation client = null; lock (clients) { if (i >= clients.Count) { continue; } client = clients[i]; } if (!client.client.Connected) { lock (clients) { clients.RemoveAt(i); } i--; continue; } byte[] buffer = new byte[1024]; int bytesRead = client.client.Receive(buffer); if (bytesRead != 0) { client.bufferString += System.Text.Encoding.ASCII.GetString(buffer.Take(bytesRead).ToArray()); string[] splits = client.bufferString.Split('\n'); if (splits.Length > 1) { client.WriteProect.WaitOne(); client.lastRead = splits[splits.Length - 2]; client.bufferString = splits[splits.Length - 1]; client.WriteProect.ReleaseMutex(); } } } } catch { } } }
public static void SendResults(SocketInformation s, object o) { byte[] data = null; using (Socket socket = new Socket(s)) { try { socket.Send(data); socket.Close(); } catch { //not sure what we want to do here. } } }
internal void method_5(SocketInformation socketInformation_0, int int_0) { SocketConnection Message = new SocketConnection(Convert.ToUInt32(int_0), socketInformation_0); this.Message1_0[int_0] = Message; HabboIM.GetGame().GetClientManager().method_8((uint)int_0, ref Message); if (HabboIM.GetConfig().data["emu.messages.connections"] == "1") { Logging.WriteLine(string.Concat(new object[] { ">> Connection [", int_0, "] from [", Message.String_0, "]" })); } }
void CreateSocket(SocketInformation mInfomation) { Socket s = new Socket(mInfomation); if (s.Connected) { ClientSocket cSock = new ClientSocket(); cSock.m_ConnectTime = DateTime.Now; cSock.cSocket = s; cSock.m_LastVisit = DateTime.Now; cSock.mBuffers = new List <byte>(4096); cSock.mReceiveBytes = new byte[2048]; cSock.SocketID = cSock.cSocket.Handle.ToInt32(); cSock.sRemoteIPAndPort = s.RemoteEndPoint.ToString(); cSock.sLocalIPAndPort = s.LocalEndPoint.ToString(); s.BeginReceive(cSock.mReceiveBytes, 0, 2048, SocketFlags.None, new AsyncCallback(ReceiveCallBack), cSock); //Console.WriteLine("接受服务器端传来的连接:" + s.RemoteEndPoint.ToString()); //AddClientToList(cSock); } }
public Socket(SocketInformation socketInformation) { }