本文整理汇总了C#中Main.acceptance方法的典型用法代码示例。如果您正苦于以下问题:C# Main.acceptance方法的具体用法?C# Main.acceptance怎么用?C# Main.acceptance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Main
的用法示例。
在下文中一共展示了Main.acceptance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: waitForConnection
public void waitForConnection()
{
try
{
//Creating listening Socket
this.listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7000);
Console.WriteLine("waiting for server response");
//Starts listening
this.listener.Start();
//Establish connection upon server request
while (true)
{
connection = listener.AcceptSocket(); //connection is connected socket
//Console.WriteLine("Connetion is established");
//Fetch the messages from the server
int asw = 0;
//create a network stream using connection
NetworkStream serverStream = new NetworkStream(connection);
List<Byte> inputStr = new List<byte>();
//fetch messages from server
while (asw != -1)
{
asw = serverStream.ReadByte();
inputStr.Add((Byte)asw);
}
String messageFromServer = Encoding.UTF8.GetString(inputStr.ToArray());
Main torkenizer = new Main();
//Console.Write("Response from server to join "+torkenizer.serverJoinReply(messageFromServer));
Console.WriteLine(messageFromServer);
if (messageFromServer.StartsWith("I") && messageFromServer.EndsWith("#"))
{
torkenizer.initiation(messageFromServer);
}
else if(messageFromServer.StartsWith("S") && messageFromServer.EndsWith("#"))
{
torkenizer.acceptance(messageFromServer);
}
else if (messageFromServer.StartsWith("G") && messageFromServer.EndsWith("#"))
{
}
serverStream.Close(); //close the netork stream
}
}
catch (Exception e)
{
Console.WriteLine("Communication (RECEIVING) Failed! \n " + e.StackTrace);
errorOcurred = true;
}
finally
{
if (connection != null)
if (connection.Connected)
connection.Close();
if (errorOcurred)
this.waitForConnection();
}
}