Created
February 1, 2016 08:42
-
-
Save sudipto80/d9f3eb0d68f96f3b37a8 to your computer and use it in GitHub Desktop.
Example for API Mining
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Net.Sockets; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TcpListener serverSocket = new TcpListener(8888); | |
int requestCount = 0; | |
TcpClient clientSocket = default(TcpClient); | |
serverSocket.Start(); | |
Console.WriteLine(" >> Server Started"); | |
clientSocket = serverSocket.AcceptTcpClient(); | |
Console.WriteLine(" >> Accept connection from client"); | |
requestCount = 0; | |
while ((true)) | |
{ | |
try | |
{ | |
requestCount = requestCount + 1; | |
NetworkStream networkStream = clientSocket.GetStream(); | |
byte[] bytesFrom = new byte[10025]; | |
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize); | |
string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom); | |
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")); | |
Console.WriteLine(" >> Data from client - " + dataFromClient); | |
string serverResponse = "Last Message from client" + dataFromClient; | |
Byte[] sendBytes = Encoding.ASCII.GetBytes(serverResponse); | |
networkStream.Write(sendBytes, 0, sendBytes.Length); | |
networkStream.Flush(); | |
Console.WriteLine(" >> " + serverResponse); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
} | |
} | |
clientSocket.Close(); | |
serverSocket.Stop(); | |
Console.WriteLine(" >> exit"); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment