morpionReseau/go01/socketPlateauCLI.cs

60 lines
2.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
2019-01-03 11:20:16 +01:00
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
2019-01-03 11:20:16 +01:00
using System.Windows.Forms;
namespace go01
{
class socketPlateauCLI : socketPlateauBase
{
2019-01-03 11:20:16 +01:00
public delegate void OnConnected(object myObject, socketPlateauConnected myArgs);
public event OnConnected onConnected;
public delegate void OnJoinACK(object myObject, socketPlateauServACKArgs myArgs);
public event OnJoinACK onJoinACK;
public socketPlateauCLI(ConfigGo_S cfgGo, Goban g) : base(TypeSocket_E.Client, cfgGo, g)
{
2019-01-03 11:20:16 +01:00
try
{
socCli = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socCli.BeginConnect(new IPEndPoint(cfgGo.IpServeur, port), new AsyncCallback(SurConnection), socCli);
}
catch (Exception ee)
{
MessageBox.Show("Connexion impossible : " + ee.Message);
}
}
public socketPlateauCLI(ConfigGo_S cfgGo, Goban g, OnJoinACK onJoinACK) : this(cfgGo, g)
{
this.onJoinACK = onJoinACK;
}
public socketPlateauCLI(ConfigGo_S cfgGo, Goban g, OnConnected onConnected) : this(cfgGo, g)
{
this.onConnected = onConnected;
}
private void SurConnection(IAsyncResult iAR)
{
Socket sTmp = (Socket)iAR.AsyncState;
if (sTmp.Connected) {
connexionEtablie = true;
try { onConnected(this, new socketPlateauConnected(cfgGo)); } catch { }
senCmd(new CommandeSocket_S(commande_E.Join, cfgGo));
InitialiserReception(sTmp);
}
else { MessageBox.Show("Serveur innacessible"); }
}
2019-01-03 11:20:16 +01:00
protected override void Received(CommandeSocket_S cmd)
{
throw new NotImplementedException();
}
}
}