public static int SendReceiveTest2(TcpClient server, OpersEnum opersEnum) { byte[] msg = Encoding.UTF8.GetBytes("This is a test"); byte[] bytes = new byte[256]; try { // Blocks until send returns. int byteCount = server.Client.Send(new[] {(byte) opersEnum}, SocketFlags.None); Console.WriteLine("Sent {0} bytes.", byteCount); // Get reply from the server. byteCount = server.Client.Receive(bytes, SocketFlags.None); Console.WriteLine(byteCount); //if (byteCount > 0) // Console.WriteLine(Encoding.UTF8.GetString(bytes)); } catch (SocketException e) { Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode); return (e.ErrorCode); } catch (Exception exception) { MessageBox.Show("Unable to comunicate with PhD" + exception.Message); } return 0; }
public static int SendReceiveTest2(TcpClient server, OpersEnum opersEnum) { byte[] msg = Encoding.UTF8.GetBytes("This is a test"); byte[] bytes = new byte[256]; try { // Blocks until send returns. int byteCount = server.Client.Send(new[] { (byte)opersEnum }, SocketFlags.None); Console.WriteLine("Sent {0} bytes.", byteCount); // Get reply from the server. byteCount = server.Client.Receive(bytes, SocketFlags.None); Console.WriteLine(byteCount); //if (byteCount > 0) // Console.WriteLine(Encoding.UTF8.GetString(bytes)); } catch (SocketException e) { Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode); return(e.ErrorCode); } catch (Exception exception) { MessageBox.Show("Unable to comunicate with PhD" + exception.Message); } return(0); }