本文整理汇总了C#中System.Net.Sockets.TcpListener.BeginAcceptSocket方法的典型用法代码示例。如果您正苦于以下问题:C# TcpListener.BeginAcceptSocket方法的具体用法?C# TcpListener.BeginAcceptSocket怎么用?C# TcpListener.BeginAcceptSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpListener
的用法示例。
在下文中一共展示了TcpListener.BeginAcceptSocket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
GMSKeys.Initialize();
{
// Quick test
ITEMS = new Dictionary<short, ItemEquip>();
ITEMS.Add(1, new ItemEquip(1113017)
{
StatusFlags = 0x0714,
Potential1 = 40356,
Potential2 = 30041,
Potential3 = 30044,
Potential4 = 12011,
Potential5 = 2014,
Potential6 = 2014,
SocketState = 0x00FF,
Nebulite2 = 1001,
Nebulite1 = 2001,
Nebulite3 = 3400,
});
//File.WriteAllText("import.xml", ITEMS.Serialize());
if (File.Exists("import.xml"))
{
ITEMS = File.ReadAllText("import.xml").Deserialize<Dictionary<short, ItemEquip>>();
}
}
if (ITEMS == null)
ITEMS = new Dictionary<short, ItemEquip>();
{
TcpListener listener = new TcpListener(System.Net.IPAddress.Any, 8484);
listener.Start();
AsyncCallback EndAccept = null;
EndAccept = (a) =>
{
new Client(listener.EndAcceptSocket(a));
Console.WriteLine("accepted");
listener.BeginAcceptSocket(EndAccept, null);
};
listener.BeginAcceptSocket(EndAccept, null);
}
Console.ReadLine();
}
示例2: Connect4Service
private Connect4ClientConnection waiting; //Player 1 - put into a game as soon as Player 2 is identified. Set to null once the game starts
#endregion Fields
#region Constructors
/// <summary>
/// Constructs a new Connect4Service object. Takes values to set the port it listens on,
/// as well as a time limit for games held on this server.
/// Throws InvalidOperationException if timelimit < 1, or the port number is out of range
/// or already being listened on.
/// </summary>
/// <param name="portNumber">Port for the server to listen on</param>
/// <param name="timeLimit">Time limit for users in games on this server</param>
public Connect4Service(int portNumber, int _timeLimit, WhoGoesFirst _choosingMethod)
{
if (_timeLimit <= 0)
{
throw new InvalidOperationException("time limit must be positive");
}
if (portNumber > IPEndPoint.MaxPort || portNumber < IPEndPoint.MinPort)
{
throw new InvalidOperationException("invalid port number");
}
choosingMethod = _choosingMethod;
games = new List<Connect4Game>();
needToIdentify = new List<Connect4ClientConnection>();
waiting = null;
timeLimit = _timeLimit;
server = new TcpListener(IPAddress.Any, portNumber);
try
{
server.Start();
}
catch (SocketException)
{
throw new InvalidOperationException("port already taken (or something like that)");
}
server.BeginAcceptSocket(ConnectionRequested, null);
isShuttingDown = false;
}
示例3: BoggleServer
/// <summary>
/// Constructor used to initialize a new BoggleServer. This will initialize the GameLength
/// and it will build a dictionary of all of the valid words from the DictionaryPath. If an
/// optional string was passed to this application, then it will build a BoggleBoard from
/// the supplied string. Otherwise it will build a BoggleBoard randomly.
/// </summary>
/// <param name="GameLength">The length that the Boggle game should take.</param>
/// <param name="DictionaryPath">The filepath to the dictionary that should be used to
/// compare words against.</param>
/// <param name="OptionalString">An optional string to construct a BoggleBoard with.</param>
public BoggleServer(int GameLength, string DictionaryPath, string OptionalString)
{
try
{
this.UnderlyingServer = new TcpListener(IPAddress.Any, 2000);
this.GameLength = GameLength;
this.DictionaryWords = new HashSet<string>(File.ReadAllLines(DictionaryPath));
this.WaitingPlayer = null;
this.CommandReceived = new Object();
this.ConnectionReceivedLock = new Object();
if (OptionalString != null)
this.OptionalString = OptionalString;
Console.WriteLine("The Server has Started on Port 2000");
// Start the server and begin accepting clients.
UnderlyingServer.Start();
UnderlyingServer.BeginAcceptSocket(ConnectionReceived, null);
}
// If any exception occured when starting the sever or connecting clients,
// print out an error message and the stacktrace where the error occured.
catch (Exception e)
{
Console.WriteLine("An Exception Occured When Building the BoggleServer:");
Console.WriteLine(e.ToString());
}
}
示例4: Start
public void Start()
{
_stop = false;
_listener = new TcpListener(IPAddress.Any, _port);
_listener.Start();
_listener.BeginAcceptSocket(OnAcceptSocket, null);
}
示例5: ConnectionManager
/// <summary>
/// Constructor to create the list of connects and create
/// a new thread to wait/accept new connections
/// </summary>
public ConnectionManager(String host, String p)
{
Log.WriteMessage("WhitStream Server Started.", Log.eMessageType.Normal);
m_ipAddress = IPAddress.Parse(host);
m_listenPort = int.Parse(p);
//Initialize the list to hold no connections and default capacity
m_connectionList = new List<Connection>();
//Initialize the list to hold all ports from 4001 to 4010
m_availablePorts = new Queue<int>(10);
for (int i = 4001; i <= 4010; i++)
{
m_availablePorts.Enqueue(i);
}
Log.WriteMessage("Waiting for connections....", Log.eMessageType.Debug);
//Register a new TcpListener
m_incomingListener = new TcpListener(m_ipAddress, m_listenPort);
m_incomingListener.Start();
m_incomingListener.BeginAcceptSocket(new AsyncCallback(Accept_Socket), null);
m_checkThread = new Thread(CheckConnections);
m_checkThread.Start();
}
示例6: Framework
/// <summary>
/// Creates a new NPCServer
/// </summary>
internal Framework(string OptionsFile = "settings.ini")
{
// Default PM
this.NCMsg = CString.tokenize ("I am the npcserver for\nthis game server. Almost\nall npc actions are controled\nby me.");
// Create Compiler
Compiler = new GameCompiler (this);
// Create Player Manager
PlayerManager = new Players.PlayerList (this, GSConn);
AppSettings settings = AppSettings.GetInstance ();
settings.Load (OptionsFile);
// Connect to GServer
GSConn = new GServerConnection (this);
this.ConnectToGServer();
// Setup NPC-Control Listener
cNCAccept = new AsyncCallback (NCControl_Accept);
this.UPnPOpenPort();
NCListen = new TcpListener (IPAddress.Parse (this.LocalIPAddress ()), settings.NCPort);
NCListen.Start ();
NCListen.BeginAcceptSocket (cNCAccept, NCListen);
settings.Save ();
// Setup Timer
//timeBeginPeriod(50);
//TimerHandle = new TimerEventHandler(RunServer);
//TimerId = timeSetEvent(50, 0, TimerHandle, IntPtr.Zero, EVENT_TYPE);
}
示例7: StartListener
public void StartListener(string ip,int port)
{
socket = new Socket(SocketType.Stream,ProtocolType.Tcp);
listener = new TcpListener(new IPEndPoint(IPAddress.Parse(ip), port));
listener.Start();
listener.BeginAcceptSocket(clientConnect, listener);
}
示例8: BoggleServer
/// <summary>
/// Creates a BoggleServer that listens for connections on port 2000.
/// </summary>
public BoggleServer(int gameTime, HashSet<string> dictionary, string boardConfiguration)
{
// Initialize fields.
_PORT = 2000;
_server = new TcpListener(IPAddress.Any, _PORT);
_waitingPlayer = null;
_allMatches = new HashSet<Match>();
_lock = new object();
_gameTime = gameTime;
_dictionary = dictionary;
_boardConfiguration = boardConfiguration;
// Start the server.
_server.Start();
// Start listening for a client to connect.
_server.BeginAcceptSocket(ConnectionReceived, null);
// Create a timer with a one second interval.
timer = new System.Timers.Timer(1000);
// Hook up the Elapsed event for the timer.
timer.Elapsed += OneSecondHasPassed;
timer.Enabled = true;
// Keep this program alive
Thread t = new Thread(stayAlive);
t.Start();
}
示例9: StandardTcpServer
//----------------------------------------------------------------------
//Construction, Destruction
//----------------------------------------------------------------------
/// <summary>
/// Creating server socket
/// </summary>
/// <param name="port">Server port number</param>
public StandardTcpServer(int port)
{
connectedSockets = new Dictionary<IPEndPoint, Socket>();
tcpServer = new TcpListener(IPAddress.Any, port);
tcpServer.Start();
tcpServer.BeginAcceptSocket(EndAcceptSocket, tcpServer);
}
示例10: resetSocketB_Click
void resetSocketB_Click(object sender, EventArgs e)
{
foreach (var item in myList)
{
item.Stop();
}
myList.Clear();
IPAddress ipAd = IPAddress.Parse(SettingsWin.host.Text);
// use local m/c IP address, and
// use the same in the client
/* Initializes the Listener */
//TODO : make handle multi listeners !!
String [] a = SettingsWin.Port.Text.Split(',');
foreach (String portt in a ) {
try {
var tempList = new TcpListener(IPAddress.Any, int.Parse(portt));
tempList.Start();
tempList.BeginAcceptSocket(this.AcceptClient, tempList);
myList.AddLast(tempList);
}
catch {
}
}
}
示例11: Mainwin
public Mainwin()
{
InitializeComponent();
cms = this.contextMenuStrip1; // providing a cms for rows
for (int i = 0; i < 21; i++) {
this.grid1.addRow();
}
Host = SettingsWin.host.Text;
ports = int.Parse(SettingsWin.Port.Text ) ;
SettingsWin.resetSocketB.Click += resetSocketB_Click;
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
// use local m/c IP address, and
// use the same in the client
/* Initializes the Listener */
var tempList = new TcpListener(IPAddress.Any, 5202);
myList.AddLast(tempList);
tempList.Start();
tempList.BeginAcceptSocket(this.AcceptClient,tempList);
timer1.Start();
}
示例12: StartProcessing
public override void StartProcessing()
{
_options.Validate();
_listener = new TcpListener(_options.Endpoint);
_listener.Start();
_listener.BeginAcceptSocket(AcceptCallback, _listener);
}
示例13: Start
internal bool Start(ushort port) {
if (Running) { throw new Exception("Listener is already running."); }
listen = new TcpListener(IPAddress.Any,port);
try { listen.Start(); }
catch { Stop(); return false; }
listen.BeginAcceptSocket(new AsyncCallback(Accept),null);
return true;
}
示例14: BoggleServer
/// <summary>
/// #ctor
/// makes server with new client lis
/// </summary>
/// <param name="port"></param>
public BoggleServer(int port)
{
server = new TcpListener(IPAddress.Any,port);
clients = new Queue<Tuple<StringSocket, string>>();
currentGames = new HashSet<game>();
server.Start();
server.BeginAcceptSocket(ConnectionAccept, null);
}
示例15: Start
public void Start(int port)
{
if (RequestHandler == null)
throw new InvalidOperationException("You must hook the RequestHandler delegate first.");
_listener = new TcpListener(IPAddress.Any, port);
_listener.Start(500);
_listener.BeginAcceptSocket(OnAccept, null);
}