Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Net.Sockets;
- using System.Text;
- namespace FitnesTestServer
- {
- class SocketHelper
- {
- TcpClient mscClient;
- string mstrMessage;
- string mstrResponse;
- byte[] bytesSent;
- char[] charsSent;
- public void processMsg(TcpClient client, NetworkStream stream, byte[] bytesReceived)
- {
- // Handle the message received and
- // send a response back to the client.
- mstrMessage = Encoding.UTF8.GetString(bytesReceived, 0, bytesReceived.Length);
- mscClient = client;
- mstrMessage = mstrMessage.Substring(0, 50);
- string[] values = new string[7];
- int[] valuesTwo = new int[3];
- double[] valuesThree = new double[3];
- //Convert message to charArray
- char[] messageArray = mstrMessage.ToCharArray();
- //Words counter
- int tempArrayCount = 0,
- valuesTwoCounter = 0,
- valuesThreeCounter = 0;
- //Convert charArray to string array
- for (int i = 0; i < messageArray.Length; i++)
- {
- //The end of the cycle if the end of the string
- if (messageArray[i] == '\0') break;
- //Count counted strings
- if (messageArray[i] == '_')
- {
- tempArrayCount++;
- }
- else
- {
- //Build strings
- values[tempArrayCount] = values[tempArrayCount] + messageArray[i];
- }
- }
- //Converting from string to int and double
- for(int i = 1; i < values.Length; i++)
- {
- if(i < 4)
- {
- valuesTwo[valuesTwoCounter] = System.Convert.ToInt32(values[i]);
- valuesTwoCounter++;
- } else
- {
- valuesThree[valuesThreeCounter] = System.Convert.ToDouble(values[i]);
- valuesThreeCounter++;
- }
- }
- Rasschet calculation = new Rasschet();
- calculation.calculate(values[0],
- valuesTwo[0], valuesTwo[1], valuesTwo[2],
- valuesThree[0], valuesThree[1], valuesThree[2]);
- bytesSent = Encoding.ASCII.GetBytes(calculation.getResult());
- stream.Write(bytesSent, 0, bytesSent.Length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement