public SimpleNetwork_Client(protocolFunction protAnalyseFunction, int iBufferlength, string network_AKey, IPAddress ip, short port, AddressFamily familyType, SocketType socketType, ProtocolType protocolType) { this.protAnalyseFunction = protAnalyseFunction; this.Network_AKey = network_AKey; endpoint = new socketEndpointCommunication(iBufferlength, ip, port, familyType, socketType, protocolType); endpointCommunicationIsDeclared = true; }
private void receiveCallback(IAsyncResult result) { lock (thisLock) { socketEndpointCommunication serverMessage = (socketEndpointCommunication)result.AsyncState; try { int bytestoread = serverMessage.getSocket().EndReceive(result); string text = Encoding.UTF8.GetString(serverMessage.getBuffer(), 0, bytestoread).Replace("\0", string.Empty); if (text != "") { serverMessage.getSocket().BeginReceive(serverMessage.getBuffer(), 0, endpoint.getBufferLength(), SocketFlags.None, new AsyncCallback(receiveCallback), serverMessage); protAnalyseFunction(text); serverMessage.clearBuffer(); } } catch (Exception e) { //MessageBox.Show(e.ToString()); return; } } }
//Functions public void setSocketEndpointCommunication(int iBufferLength, IPAddress ip, short port, AddressFamily familyType, SocketType socketType, ProtocolType protocolType) { endpoint = new socketEndpointCommunication(iBufferLength, ip, port, familyType, socketType, protocolType); endpointCommunicationIsDeclared = true; }