/// <summary> /// This takes the incoming data byte stream, converts it to a string and /// allows the clients to do whatever they need with it. /// </summary> /// <param name="IncomingData">The incoming byte buffer.</param> /// <param name="IncomingDataLength">The length of said byte buffer.</param> public SocketServerClientEventArgs(string IPAddress, SocketClientBuffer Socket) { //Set the IP this._IPAddress = IPAddress; //Set the socket. this._Socket = Socket; }
private void DataWasRecieved(byte [] pData, int pDataLength, SocketClientBuffer pSocket) { SocketServerDataEventArgs tmpEventArgs = new SocketServerDataEventArgs(pData, pDataLength, pSocket); this._BytesReceived += pDataLength; OnDataRecieved(tmpEventArgs); }
/// <summary> /// This takes the incoming data byte stream, converts it to a string and /// allows the clients to do whatever they need with it. /// </summary> /// <param name="IncomingData">The incoming byte buffer.</param> /// <param name="IncomingDataLength">The length of said byte buffer.</param> public TelnetServerCommandEventArgs(string pCommand, SocketClientBuffer pSocket) { //Set the IP this._Command = pCommand; //Set the socket. this._Socket = pSocket; }
/// <summary> /// This takes the incoming data byte stream, converts it to a string and /// allows the clients to do whatever they need with it. /// </summary> /// <param name="pIncomingData">The incoming byte buffer.</param> /// <param name="pIncomingDataLength">The length of said byte buffer.</param> public SocketServerDataEventArgs(byte [] pIncomingData, int pIncomingDataLength, SocketClientBuffer pSocket) { //Set up the byte buffer first this._IncomingDataLength = pIncomingDataLength; this._IncomingDataBytes = pIncomingData; //Now encode the ascii string this._IncomingDataString = System.Text.Encoding.ASCII.GetString(pIncomingData, 0, pIncomingDataLength); //Now set the Socket it came in on this._Socket = pSocket; }
public SocketServerDataEventArgs(string pIncomingLine, SocketClientBuffer pSocket) { //Set up the string first this._IncomingDataString = pIncomingLine; //Now the byte buffer this._IncomingDataBytes = System.Text.Encoding.ASCII.GetBytes(pIncomingLine); this._IncomingDataLength = this._IncomingDataBytes.Length; //Now set the Socket it came in on this._Socket = pSocket; }
public void SendData(byte[] pData, SocketClientBuffer pClient) { try { pClient.Sock.Send(pData); this._BytesSent += pData.Length; } catch { // If the send fails the close the connection //Raise the disconnected event this.ClientHasDisconnected(pClient.Sock.RemoteEndPoint.ToString(), pClient); this.WriteToLog(string.Concat("Client Disconnected from [", pClient.Sock.RemoteEndPoint, "]"), 2); //Kill the socket pClient.Sock.Close(); _ClientsConnected.Remove(pClient); return; } }
/// <summary> /// Add the given connection to our list of clients. /// </summary> /// <param name="pSocket">Connection socket</param> public void NewConnection(Socket pSocket) { // This will block accepting sockets until a client is shuffled to // a new socket in the buffer. This should stop any issues if // the server is DOS'd because of it's limit on connection // speed, however, load would be somewhat limited (i.e. you could // not have more than 1000 connections in a second). // // For my current uses of this library these limitations should be fine. SocketClientBuffer tmpClient = new SocketClientBuffer(pSocket); _ClientsConnected.Add(tmpClient); tmpClient._RemoteInformation = pSocket.RemoteEndPoint.ToString(); this.WriteToLog(string.Concat("Client Connected from [", tmpClient._RemoteInformation, "]"), 1); tmpClient.Die += new SocketBufferEventHandler(ClientDied); //Raise the connection event this.ClientHasConnected(tmpClient.Sock.RemoteEndPoint.ToString(), tmpClient); tmpClient.SetupRecieveCallback(this); }
public void SendData(string pData, SocketClientBuffer pSocket) { //Send some data back to the server _SocketServer.SendData(pData, pSocket); }
public void SendLineFeed(SocketClientBuffer pSocket) { _SocketServer.SendData(string.Concat(this._NewLine), pSocket); }
public void SendPrompt(SocketClientBuffer pSocket) { _SocketServer.SendData(string.Concat(this._NewLine, this._TelnetPrompt), pSocket); }
//Event firing functions private void CommandIsRecieved(string pCommand, SocketClientBuffer pSocket) { TelnetServerCommandEventArgs tmpEventArgs = new TelnetServerCommandEventArgs(pCommand, pSocket); OnCommandRecieved(tmpEventArgs); }
private void ClientHasDisconnected(string pClientIP, SocketClientBuffer pSocket) { SocketServerClientEventArgs tmpEventArgs = new SocketServerClientEventArgs(pClientIP, pSocket); OnClientDisconnected(tmpEventArgs); }
public SocketBufferEventArgs(SocketClientBuffer pClient) { //Nothing fancy to be done, this is a data encapsulation class this._Client = pClient; }
/// <summary> /// Recieve the data, and handle it in the class. /// </summary> /// <param name="pAsyncResult"></param> public void OnRecievedData(IAsyncResult pAsyncResult) { SocketClientBuffer tmpClientBuffer = (SocketClientBuffer)pAsyncResult.AsyncState; byte [] tmpRecievedBuffer = tmpClientBuffer.GetRecievedData(pAsyncResult); // If no data was recieved then the connection is probably dead if (tmpRecievedBuffer.Length < 1) { //Raise the disconnected event if (tmpClientBuffer._CleanUp == true) { this.ClientHasDisconnected(tmpClientBuffer._RemoteInformation, tmpClientBuffer); } else { this.ClientHasDisconnected(tmpClientBuffer.Sock.RemoteEndPoint.ToString(), tmpClientBuffer); //Kill the socket tmpClientBuffer.Sock.Close(); this._ClientsConnected.Remove(tmpClientBuffer); } this.WriteToLog(string.Concat("Client Disconnected from [", tmpClientBuffer._RemoteInformation, "]"), 2); return; } else { //Raise the recieved data event this.DataWasRecieved(tmpRecievedBuffer, tmpRecievedBuffer.Length, tmpClientBuffer); //Walk through the bytes that just came through and such. //This could be optional? We may not need this granularity on incoming data. foreach (byte tmpByte in tmpRecievedBuffer) { switch (tmpByte) { case 10: //A CR was recieved if (tmpClientBuffer._LineBuffer.Length > 0) { string tmpBuffer = tmpClientBuffer._LineBuffer.ToString(); //Clear the linebuffer tmpClientBuffer._LineBuffer.Remove(0, tmpClientBuffer._LineBuffer.Length); //Now fire the event this.LineWasRecieved(tmpBuffer, tmpClientBuffer); } this.NewLineWasRecieved(tmpClientBuffer); tmpClientBuffer._InputTouched = true; break; case 127: //A Backspace was recieved, remove the end character if (tmpClientBuffer._LineBuffer.Length > 0) { tmpClientBuffer._LineBuffer.Remove(tmpClientBuffer._LineBuffer.Length - 1, 1); this.BackspaceWasRecieved(tmpClientBuffer); } break; default: //See if it's an "ok" ascii character if ((tmpByte > 13) && (tmpByte < 147) && (tmpClientBuffer._LineBuffer.Length < 300)) { //Append it to our line buffer tmpClientBuffer._LineBuffer.Append(Convert.ToChar(tmpByte)); } break; } } } tmpClientBuffer.SetupRecieveCallback(this); }
public void SendDataPlusBuffer(string pData, SocketClientBuffer pClient) { this.SendDataPlusBuffer(System.Text.Encoding.ASCII.GetBytes(pData), pClient); }
private void BackspaceWasRecieved(SocketClientBuffer pSocket) { SocketServerDataEventArgs tmpEventArgs = new SocketServerDataEventArgs(Convert.ToChar(127).ToString(), pSocket); OnBackspaceRecieved(tmpEventArgs); }
private void TabWasRecieved(SocketClientBuffer pSocket) { SocketServerDataEventArgs tmpEventArgs = new SocketServerDataEventArgs("\t", pSocket); OnTabRecieved(tmpEventArgs); }
private void NewLineWasRecieved(SocketClientBuffer pSocket) { SocketServerDataEventArgs tmpEventArgs = new SocketServerDataEventArgs("\n", pSocket); OnNewLineRecieved(tmpEventArgs); }
private void LineWasRecieved(string pLine, SocketClientBuffer pSocket) { SocketServerDataEventArgs tmpEventArgs = new SocketServerDataEventArgs(pLine, pSocket); OnLineRecieved(tmpEventArgs); }