Console.ReadKey(true);
while (insim.IsConnected) {
Thread.Sleep(200);
}
<?php
public class TcpSocket {
private const int BufferSize = 1024;
private TcpClient _client;
private NetworkStream _stream;
private byte[] _temp = new byte[BufferSize];
private List<byte> _buffer = new List<byte>(BufferSize);
public TcpSocket() {
_client = new TcpClient();
_client.Client.NoDelay = true;
}
public async Task ConnectAsync(string host, int port) {
await _client.ConnectAsync(host, port);
_stream = _client.GetStream();
HandleReceive();
}
public void Close() {
if (_stream != null) {
_stream.Close();
}
_client.Close();
}
public async Task SendAsync(byte[] buffer) {
await _stream.WriteAsync(buffer, 0, buffer.Length);
}
private async void HandleReceive() {
int count = await _stream.ReadAsync(_temp, 0, _temp.Length);
if (count == 0) {
Close(); // Lost connection.
}
else {
_buffer.AddRange(_temp.Take(count));
while (_buffer.Any() && _buffer.Count >= _buffer.First()) {
int size = _buffer.First();
byte[] packet = _buffer.Take(size).ToArray();
HandlePacket(packet);
_buffer.RemoveRange(0, size);
}
HandleReceive();
}
}
private void HandlePacket(byte[] packet) {
// do something...
Debug.WriteLine(packet.Length);
}
}
?>
if (small.SubT == SmallType.SMALL_VTA && VoteAction.VOTE_RESTART == (VoteAction)small.UVal)
{
}
try
{
insim.Initialize(new InSimSettings
{
Host = IPAddress,
Port = Port,
Admin = AdminPW,
Prefix = '!',
Flags = InSimFlags.ISF_MCI | InSimFlags.ISF_CON | InSimFlags.ISF_MSO_COLS,
Interval = 50, // The interval at which updates are sent (milliseconds)
});
Logiraj("################### Uspesno konektovan: ################### ", IPAddress + "; " + Port + "; " + AdminPW + ";");
}
catch(InSimException ex)
{
Logiraj("Insim greska pri konektovanju 1",ex.ToString());
[b]// Connection to LFS has failed, exit program.
Environment.Exit(1);[/b]
}
Program.UcitajPodesavanja();
UcitajJezik();
TimerReset(insim);
UcitajPorukeIzFajla();
if (userest == true)
{
UcitajRest(insim, 0);
}
try
{
insim.Send("/msg " + uspesnakonekcija);
insim.Send(new IS_TINY { SubT = TinyType.TINY_NCN, ReqI = 255 });
insim.Send(new IS_TINY { SubT = TinyType.TINY_NPL, ReqI = 255 });
insim.Send(new IS_TINY { SubT = TinyType.TINY_SST, ReqI = 255 });
insim.Send(new IS_TINY { SubT = TinyType.TINY_RST, ReqI = 255 });
}
catch (InSimException ex)
{
Logiraj("Insim greska pri konektovanju 2", ex.ToString());
}
<?php
var insim = new InSim();
insim.Initialize(new InSimSettings {
Host = "127.0.0.1",
Port = 29999,
UdpPort = 30000,
Interval = 50, // Milliseconds
});
insim.Send("/msg I don't know what this contains...");
insim.Send(new IS_TINY { SubT = TinyType.TINY_NCN, ReqI = 255 });
insim.Send(new IS_TINY { SubT = TinyType.TINY_NPL, ReqI = 255 });
insim.Send(new IS_TINY { SubT = TinyType.TINY_SST, ReqI = 255 });
insim.Send(new IS_TINY { SubT = TinyType.TINY_RST, ReqI = 255 });
Console.ReadKey();
?>
<?php
timer.Elapsed += delegate {
if (insim.IsConnected) {
insim.Send(TinyType.TINY_RST, 5);
}
}
?>
<?php
timer.Elapsed += (sender, e) => {
};
?>