/// <summary> /// Initializes a configured SocketInfo-Object and returns it. /// </summary> /// <param name="_tcpClient"> /// the Object which contains the connected client-Object. This Object can be a TcpClient-Object /// if the TCPServer is StreamBased or a Socket-Object if the TCPServer is ByteBased. /// </param> /// <returns>Return a SocketInfo-Object witch setted variables from the _tcpClient Object</returns> public static SocketInfo getSocketInfo(Object _tcpClient) { // the String will save the EndO String remoteEndPoint = ""; switch (_tcpClient.GetType().Name) { // if the TCPServer is StreamBased case "TcpClient": // set _tcpClient as TcpClient TcpClient tcpClient = _tcpClient as TcpClient; // RemoteEndPoint if (tcpClient != null) { remoteEndPoint = tcpClient.Client.RemoteEndPoint.ToString(); } break; // if the TCPServer is ByteBased case "Socket": // set the _tcpClient as Socket Socket client = _tcpClient as Socket; // RemoteEndPoint if (client != null) { remoteEndPoint = client.RemoteEndPoint.ToString(); } break; default: // Falls ein nicht identifizierbares Object mit dieser methode aufgerufen wird return(null); } // TCP-CLient IPaddress/Port IPAddress remoteEndPoint_IPAddress = IPAddress.Parse(remoteEndPoint.Substring(0, remoteEndPoint.IndexOf(':'))); Int32 remoteEndPoint_Port = Int32.Parse(remoteEndPoint.Substring(remoteEndPoint.IndexOf(':') + 1)); // SocketInfo SocketInfo socketInfo = new SocketInfo(); //sets the variables of the SocketInfo-Object socketInfo.IPAddress = remoteEndPoint_IPAddress; // Sets the IPAddress socketInfo.Port = remoteEndPoint_Port; // Sets the Port // return the SocketInfo which contains the RemoteEndPoint information return(socketInfo); }
/// <summary> /// Initializes a configured SocketInfo-Object and returns it. /// </summary> /// <param name="_tcpClient"> /// the Object which contains the connected client-Object. This Object can be a TcpClient-Object /// if the TCPServer is StreamBased or a Socket-Object if the TCPServer is ByteBased. /// </param> /// <returns>Return a SocketInfo-Object witch setted variables from the _tcpClient Object</returns> public static SocketInfo getSocketInfo(Object _tcpClient) { // the String will save the EndO String remoteEndPoint = ""; switch(_tcpClient.GetType().Name) { // if the TCPServer is StreamBased case "TcpClient": // set _tcpClient as TcpClient TcpClient tcpClient = _tcpClient as TcpClient; // RemoteEndPoint if(tcpClient != null) remoteEndPoint = tcpClient.Client.RemoteEndPoint.ToString(); break; // if the TCPServer is ByteBased case "Socket": // set the _tcpClient as Socket Socket client = _tcpClient as Socket; // RemoteEndPoint if(client != null) remoteEndPoint = client.RemoteEndPoint.ToString(); break; default: // Falls ein nicht identifizierbares Object mit dieser methode aufgerufen wird return null; } // TCP-CLient IPaddress/Port IPAddress remoteEndPoint_IPAddress = IPAddress.Parse(remoteEndPoint.Substring(0, remoteEndPoint.IndexOf(':'))); Int32 remoteEndPoint_Port = Int32.Parse(remoteEndPoint.Substring(remoteEndPoint.IndexOf(':') + 1)); // SocketInfo SocketInfo socketInfo = new SocketInfo(); //sets the variables of the SocketInfo-Object socketInfo.IPAddress = remoteEndPoint_IPAddress; // Sets the IPAddress socketInfo.Port = remoteEndPoint_Port; // Sets the Port // return the SocketInfo which contains the RemoteEndPoint information return socketInfo; }
public TCPServer_StreamBasedClient_EventArgs_ClientConnect(TcpClient _tcpClient) { this.tcpClient = _tcpClient; this.socketInfo = SocketInfo.getSocketInfo(_tcpClient); }