本文整理汇总了C#中CustomNetworking.StringSocket类的典型用法代码示例。如果您正苦于以下问题:C# StringSocket类的具体用法?C# StringSocket怎么用?C# StringSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringSocket类属于CustomNetworking命名空间,在下文中一共展示了StringSocket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Connect
/// <summary>
/// Connect to the server at the given hostname and port and with the given name of username and
/// password.
/// </summary>
public bool Connect(String hostname, int port, String password)
{
try
{
TcpClient client;
//Case 1: Using IP
IPAddress address;
if (IPAddress.TryParse(hostname, out address))
{
client = new TcpClient();
client.Connect(address, port);
}
else
{
//Case 2: Using DNS
client = new TcpClient(hostname, port);
}
socket = new StringSocket(client.Client, UTF8Encoding.Default);
//PASSWORD[esc]password\n
char esc = (char)27;
socket.BeginSend("PASSWORD" + esc + password + "\n", (e, p) => { }, null);
socket.BeginReceive(LineReceived, null);
return true;
}
catch
{
return false;
}
}
开发者ID:unaveed,项目名称:Spreadsheet,代码行数:35,代码来源:Client.cs
示例2: Connect
public void Connect(string hostname, int port, string clientPassword)
{
// initial connection to the server
if (clientSSocket == null)
{
password = clientPassword;
try
{
TcpClient client = new TcpClient(hostname, port);
clientSSocket = new StringSocket(client.Client, UTF8Encoding.Default);
clientSSocket.BeginSend("PASSWORD" + "\\e" + password + "\n", (ex, p) => { }, null);
clientSSocket.BeginReceive(LineReceived, null);
}
catch (SocketException e)
{
Console.WriteLine(e.Message);
}
}
// not sure if this part is necessary?
else
{
//clientSSocket.Close(); we don't want to close the socket unless the client is disconnecting
TcpClient client = new TcpClient(hostname, port);
clientSSocket = new StringSocket(client.Client, UTF8Encoding.Default);
clientSSocket.BeginSend("PASSWORD"+ "\\e" + password + "\n", (ex, p) => { }, null);
clientSSocket.BeginReceive(LineReceived, null);
}
}
开发者ID:hodgeskyjon,项目名称:3505_Spring_Project,代码行数:28,代码来源:SpreadsheetClientModel.cs
示例3: TestBasicWord
public void TestBasicWord()
{
TcpListener server = null;
TcpClient client1 = null;
TcpClient client2 = null;
server = new TcpListener(IPAddress.Any, 4042);
server.Start();
client1 = new TcpClient("localhost", 4042);
client2 = new TcpClient("localhost", 4042);
Socket serverSocket = server.AcceptSocket();
Socket client1Socket = client1.Client;
Socket client2Socket = client2.Client;
StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
StringSocket player1Socket = new StringSocket(client1Socket, new UTF8Encoding());
StringSocket player2Socket = new StringSocket(client2Socket, new UTF8Encoding());
BoggleServer.BoggleServer.Player player1 = new BoggleServer.BoggleServer.Player("ryan", player1Socket);
BoggleServer.BoggleServer.Player player2 = new BoggleServer.BoggleServer.Player("ryan2", player2Socket);
BoggleServer.BoggleServer.Match match = new BoggleServer.BoggleServer.Match(
player1, player2, 60, new HashSet<string>(System.IO.File.ReadAllLines(@"..\..\..\Resources\Dictionary.txt")), "horstoaeaggdpple");
match.ReceivedPlayer1Data("word horse", null, player1Socket);
Assert.AreEqual(2, player1.Score);
Assert.IsTrue(player1.UniqueLegalWords.Contains("HORSE"));
}
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:30,代码来源:BoggleServerTest.cs
示例4: User
public User(string _name, StringSocket _socket)
{
Name = _name;
socket = _socket;
Terminated = false;
socket.BeginReceive(LineReceivedFromUser, socket);
}
开发者ID:unaveed,项目名称:Spreadsheet,代码行数:8,代码来源:User.cs
示例5: Connect
/// <summary>
/// Connect to the server at the given hostname and port and with the given name.
/// </summary>
public void Connect(string hostname, int port)
{
// Connect or throw exception
_client = new TcpClient(hostname, port);
// Create a StringSocket for communicating with the server.
_stringSocket = new StringSocket(_client.Client, UTF8Encoding.Default);
}
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:11,代码来源:BoggleClientModel.cs
示例6: Connect
//make sure the client isn't already connected
//then connect
public void Connect(int port, string hostName)
{
if (ss == null)
{
TcpClient client = new TcpClient(hostName, port);
ss = new StringSocket(client.Client, UTF8Encoding.Default);
IsConnected = true;
}
}
开发者ID:ryoia,项目名称:BoggleGames,代码行数:11,代码来源:BoggleClientModel.cs
示例7: Connect
/// <summary>
/// connects on the given port and ip
/// </summary>
/// <param name="port"></param>
/// <param name="ip"></param>
public void Connect(int port, string ip)
{
if (socket == null)
{
TcpClient client = new TcpClient(ip, port);
socket = new StringSocket(client.Client, UTF8Encoding.Default);
state = State.name;
socket.BeginReceive(LineReceived, null);
}
}
开发者ID:jiiehe,项目名称:cs3500,代码行数:15,代码来源:ClientModel.cs
示例8: ConnectionReceived
/// <summary>
/// This callback method is called when a connection has been received.
/// </summary>
private void ConnectionReceived(IAsyncResult ar)
{
Socket socket = server.EndAcceptSocket(ar);
StringSocket ss = new StringSocket(socket, UTF8Encoding.Default);
// Set the StringSocket to listen for a name from the client.
ss.BeginReceive(GetReceived, ss);
// Set the server to listen for another connection.
server.BeginAcceptSocket(ConnectionReceived, null);
}
开发者ID:jimibue,项目名称:cs3505,代码行数:14,代码来源:WebServer.cs
示例9: Connect
/// <summary>
/// Connect to the server at the given hostname and port and with the give name.
/// </summary>
public void Connect(string hostname, String name)
{
if (socket == null)
{
playerName = name;
TcpClient client = new TcpClient(hostname, 2000);
socket = new StringSocket(client.Client, UTF8Encoding.Default);
socket.BeginSend("PLAY " + name + "\n", (e, p) => { }, null);
socket.BeginReceive(LineReceived, null);
}
}
开发者ID:joesturz,项目名称:Boggle,代码行数:14,代码来源:Class1.cs
示例10: Connect
/// <summary>
/// Connect to the server at the given hostname and port and with the give name.
/// </summary>
public void Connect(string hostname, int port, String name)
{
if (socket == null||!validName )
{
if (name.StartsWith("PLAY ") && name.Substring(5).Trim().Length > 0)
validName = true;
TcpClient client = new TcpClient(hostname, port);
socket = new StringSocket(client.Client, UTF8Encoding.Default);
socket.BeginSend(name + "\n", (e, p) => { }, null);
socket.BeginReceive(LineReceived, null);
}
}
开发者ID:jimibue,项目名称:cs3505,代码行数:17,代码来源:BoggleClientModel.cs
示例11: Connect
/// <summary>
/// Connect to the server at the given hostname and port, with the given name.
/// </summary>
public void Connect(String hostname, int port, String name)
{
if (socket == null)
{
TcpClient client = new TcpClient(hostname, port);
socket = new StringSocket(client.Client, UTF8Encoding.Default);
this.name = name;
this.hostname = hostname;
socket.BeginSend("PLAY " + name + "\n", (e, p) => { }, null);
socket.BeginReceive(LineReceived, null);
}
}
开发者ID:jimibue,项目名称:cs3505,代码行数:17,代码来源:BoggleClientModel.cs
示例12: Main
static void Main(string[] args)
{
//new server
TcpListener server = new TcpListener(IPAddress.Any, 4010);
server.Start();
//blocks until user connects
Socket serverSocket = server.AcceptSocket();
Console.WriteLine("hey");
// Wrap the two ends of the connection into StringSockets
StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
sendSocket.BeginSend("hi", (e, o) => { }, null);
Console.ReadLine();
}
开发者ID:jiiehe,项目名称:cs3500,代码行数:15,代码来源:Program.cs
示例13: Connect
/// <summary>
/// Connect to the server at the given hostname and port and with the give name.
/// </summary>
public void Connect(string IPAddress, String name)
{
if (socket == null)
{
try
{
TcpClient client = new TcpClient(IPAddress, 2000);
socket = new StringSocket(client.Client, UTF8Encoding.Default);
socket.BeginSend("PLAY " + name + "\n", (e, p) => { }, null);
socket.BeginReceive(LineReceived, null);
}
catch (Exception e)
{
//no such host event
noSuchHostEvent(e.Message);
}
}
}
开发者ID:matelau,项目名称:Boggle-Game-PS10,代码行数:21,代码来源:BoggleClientModel.cs
示例14: Connect
/// <summary>
/// Takes a string representing the IP Address of the server, an int with the port number and the players name.
/// It then connects to the server and sends the play message with the players name.
/// </summary>
public void Connect(String password)
{
if (socket == null || !socket.Connected())
{
// Tries to connect to the server and then send the play message
try
{
TcpClient client = new TcpClient(IP, port);
socket = new StringSocket(client.Client, UTF8Encoding.Default);
socket.BeginSend(password, (e, p) => { }, null);
socket.BeginReceive(LineReceived, null);
}
// If it is unable to connect it catches the exception and throws it on
catch (SocketException e)
{
throw e;
}
}
}
开发者ID:keivnlee,项目名称:Spreadsheet,代码行数:23,代码来源:Class1.cs
示例15: runGame
public void runGame()
{
server = new BoggleServer.BoggleServer(2000, 10, "..\\..\\..\\dictionary", "AAAABBBBCCCCDDDD");
player1 = new TcpClient("localhost", 2000);
player2 = new TcpClient("localhost", 2000);
Socket p1socket = player1.Client;
Socket p2socket = player2.Client;
p1 = new StringSocket(p1socket, new UTF8Encoding());
p2 = new StringSocket(p2socket, new UTF8Encoding());
p1.BeginSend("PLAY player1\n", (e, o) => { }, null);
p2.BeginSend("PLAY player2\n", (e, o) => { }, null);
mre = new ManualResetEvent(false);
receivedWords = new List<string>();
for (int i = 0; i < 20; i++)
{
p1.BeginReceive(callback, p1);
}
mre.WaitOne(1000);
Assert.IsTrue(receivedWords.Contains("START AAAABBBBCCCCDDDD 10 PLAYER2"));
}
开发者ID:ryoia,项目名称:BoggleGames,代码行数:21,代码来源:UnitTest1.cs
示例16: TestDisconnect
public void TestDisconnect()
{
string[] toArgs = new string[3];
toArgs[0] = "5";
toArgs[1] = "..\\..\\..\\dictionary.txt";
toArgs[2] = "TAPRVILRGTOAEUEQ";
ThreadPool.QueueUserWorkItem((e) => { BoggleServer.Main(toArgs); });
List<StringSocket> clients = new List<StringSocket>();
int CLIENT_COUNT = 2;//not a constant, I know.
for (int i = 0; i < CLIENT_COUNT; i++)
{
TcpClient tempClient = new TcpClient("localhost", 2000);
Socket tempclientSocket = tempClient.Client;
StringSocket SS = new StringSocket(tempclientSocket, new UTF8Encoding());
clients.Add(SS);
}
string clientString0 = "";
string clientString1 = "";
clients[0].BeginSend("PLAY Dylan\n", (e, p) => { }, 1);
clients[1].BeginSend("PLAY ToClose\n", (e, p) => { clients[1].BeginReceive((s, ee, pp) => { clientString1 = s; }, 1); }, 1);
Thread.Sleep(500);
clientString0 = "";
string clientString0next = "";
clients[1].Close();
clients[0].BeginReceive((s, ee, pp) => { clientString0 = s; }, 1);
clientString0next = catchMessage(clientString0, 0, "TERMINATED", clients[0]);
Assert.AreEqual("TERMINATED", clientString0next);
}
开发者ID:jiiehe,项目名称:cs3500,代码行数:37,代码来源:BoggleTests.cs
示例17: PlayerRecordsWebPage
// HELPER METHODS
/// <summary>
/// WebPage containing record of each player.
/// </summary>
private void PlayerRecordsWebPage(StringSocket ss)
{
using (MySqlConnection connect = new MySqlConnection(connectionString))
{
// Open MySqlConnection to Database
connect.Open();
MySqlCommand command = connect.CreateCommand();
MySqlDataReader reader;
// Begin to send HTML Web Page
ss.BeginSend("HTTP/1.1 200 OK\r\n", (ee, pp) => { }, null);
ss.BeginSend("Connection: close\r\n", (ee, pp) => { }, null);
ss.BeginSend("Content-Type: text/html; charset=UTF-8\r\n", (ee, pp) => { }, null);
ss.BeginSend("\r\n", (ee, pp) => { }, null);
// Store HTML Page
List<String> webPage = new List<String>();
webPage.Add("<html>");
webPage.Add("<title>Boggle Records</title>");
webPage.Add("<body>");
webPage.Add("<h1>Boggle Players Records</h1>");
webPage.Add("<table border=\"1\">");
webPage.Add("<tr><td>Player</td><td>Games Won</td><td>Games Lost</td><td>Games Tied</td></tr>");
// Sorted Dictionary to Store Wicked-Awesome Query
SortedDictionary<String, Int32[]> playerWinsLossesTies = new SortedDictionary<String, Int32[]>();
// Query for Tied (Bool), PlayerAName, PlayerBName, WinnerName, LoserName
command.CommandText = @"
SELECT Tied,
PlayerAName.PlayerName AS 'Tie A Name',
PlayerBName.PlayerName AS 'Tie B Name' ,
WinName.PlayerName AS 'Winner',
LoseName.PlayerName AS 'Loser'
FROM GameInfo AS Game
LEFT JOIN Players AS PlayerAName
ON Game.PlayerAID=PlayerAName.PlayerID
LEFT JOIN Players AS PlayerBName
ON Game.PlayerBID=PlayerBName.PlayerID
LEFT JOIN Players AS WinName
ON Game.WinnerName=WinName.PlayerID
LEFT JOIN Players AS LoseName
ON Game.LoserName=LoseName.PlayerID";
command.Parameters.Clear();
using (reader = command.ExecuteReader())
{
// For every result from the Query
while (reader.Read())
{
// If tied is false, then we know there must be a winner
if (reader.GetInt32(0) == 0)
{
String keyNameWinner;
String keyNameLoser;
try
{
keyNameWinner = reader.GetString(3);
keyNameLoser = reader.GetString(4);
}
catch
{
continue;
}
// Add one point to Winner Score
if (playerWinsLossesTies.ContainsKey(keyNameWinner))
{
playerWinsLossesTies[keyNameWinner][0] += 1;
}
else
{
playerWinsLossesTies.Add(keyNameWinner, new int[]{1,0,0});
}
// Add one point to Loser Score
if (playerWinsLossesTies.ContainsKey(keyNameLoser))
{
playerWinsLossesTies[keyNameLoser][1] += 1;
}
else
{
playerWinsLossesTies.Add(keyNameLoser, new int[] { 0, 1, 0 });
}
}
// Both Player A and Player B must be Tied
else if (reader.GetInt32(0) == 1)
{
String keyTiedPlayerA;
String keyTiedPlayerB;
try
{
keyTiedPlayerA = reader.GetString(1);
keyTiedPlayerB = reader.GetString(2);
//.........这里部分代码省略.........
开发者ID:ryoia,项目名称:BoggleGames,代码行数:101,代码来源:BS.cs
示例18: addPlayer
/// <summary>
/// Returns true once a games has two players, false otherwise
/// </summary>
/// <param name="playerName"></param>
/// <param name="socket"></param>
/// <returns></returns>
public bool addPlayer(string playerName, StringSocket socket, int game)
{
if (player1Name == null)
{
player1Name = playerName;
player1 = socket;
player1.Player = 1;
player1.Game = game;
return false;
}
else
{
player2Name = playerName;
player2 = socket;
player2.Player = 2;
player2.Game = game;
return true;
}
}
开发者ID:matelau,项目名称:Boggle-Game-PS10,代码行数:25,代码来源:BoggleGame.cs
示例19: run
public void run(int port)
{
// Create and start a server and client.
TcpListener server = null;
TcpClient client = null;
try
{
server = new TcpListener(IPAddress.Any, port);
server.Start();
client = new TcpClient("localhost", port);
// Obtain the sockets from the two ends of the connection. We are using the blocking AcceptSocket()
// method here, which is OK for a test case.
Socket serverSocket = server.AcceptSocket();
Socket clientSocket = client.Client;
// Wrap the two ends of the connection into StringSockets
StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
StringSocket receiveSocket = new StringSocket(clientSocket, new UTF8Encoding());
// This will coordinate communication between the threads of the test cases
mre1 = new ManualResetEvent(false);
mre2 = new ManualResetEvent(false);
// Make two receive requests
receiveSocket.BeginReceive(CompletedReceive1, 1);
receiveSocket.BeginReceive(CompletedReceive2, 2);
// Now send the data. Hope those receive requests didn't block!
String msg = "Hello world\nThis is a test\n";
foreach (char c in msg)
{
sendSocket.BeginSend(c.ToString(), (e, o) => { }, null);
}
// Make sure the lines were received properly.
Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
Assert.AreEqual("Hello world", s1);
Assert.AreEqual(1, p1);
Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
Assert.AreEqual("This is a test", s2);
Assert.AreEqual(2, p2);
}
finally
{
server.Stop();
client.Close();
}
}
开发者ID:jimibue,项目名称:cs3505,代码行数:51,代码来源:StringSocketTest.cs
示例20: WebServerConnectionRequested
// WEB SERVER
/// <summary>
/// Callback for Web Server Listener
/// -Creates a socket between client and server.
/// -Begins receiving data from the client (URL information)
/// -Recalls WebServerListener to listen for more page views.
/// </summary>
private void WebServerConnectionRequested(IAsyncResult result)
{
StringSocket ss = new StringSocket(webServerListener.EndAcceptSocket(result), new UTF8Encoding());
ss.BeginReceive(WebRequestServerStart, ss);
webServerListener.BeginAcceptSocket(WebServerConnectionRequested, null);
}
开发者ID:ryoia,项目名称:BoggleGames,代码行数:13,代码来源:BS.cs
注:本文中的CustomNetworking.StringSocket类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论