Skip to content

Instantly share code, notes, and snippets.

View lukasz-pyrzyk's full-sized avatar
🏠
Working from home

Łukasz Pyrzyk lukasz-pyrzyk

🏠
Working from home
View GitHub Profile
@lukasz-pyrzyk
lukasz-pyrzyk / project.json
Last active March 7, 2016 20:23
project.json of Console App (.NET Core RC1)
{
"version": "1.0.0-*"
"description": "SampleConsole Console Application",
"authors": [ "lpyrz" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"compilationOptions": {
"emitEntryPoint": true
{
"projects": [ ".", "Src" ],
"sdk": {
"version": "1.0.0-rc1-update1"
}
}
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);
int bufferSize = 1024 * 2;
// Create a TCP/IP socket.
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
try
{
listener.Bind(localEndPoint);
@lukasz-pyrzyk
lukasz-pyrzyk / TcpListenerTPLWrapper.cs
Created March 13, 2016 20:06
Decompiled code from TcpListener.
[HostProtection(SecurityAction.LinkDemand, ExternalThreading = true)]
public Task<Socket> AcceptSocketAsync()
{
return Task<Socket>.Factory.FromAsync(new Func<AsyncCallback, object, IAsyncResult>(this.BeginAcceptSocket), new Func<IAsyncResult, Socket>(this.EndAcceptSocket), (object) null);
}
TcpListener listener = new TcpListener(IPAddress.Any, 55);
listener.Start();
TcpClient client = await listener.AcceptTcpClientAsync();
byte[] request;
using (NetworkStream ns = client.GetStream())
{
using (MemoryStream ms = new MemoryStream())
{
int i;
int bufferSize = 1024 * 2;
namespace XGain
{
public interface IServer : IDisposable
{
event EventHandler<StartArgs> OnStart;
event EventHandler<MessageArgs> OnNewMessage;
event EventHandler<ErrorArgs> OnError;
Task StartSynchronously(CancellationToken token);
Task StartParallel(CancellationToken token, int? maxDegreeOfParallelism = null);
using System;
namespace XGain
{
public class ErrorArgs : EventArgs
{
public ErrorArgs(Exception ex)
{
Date = DateTime.Now;
Exception = ex;
using System;
using System.Net;
using System.Net.Sockets;
namespace XGain.Sockets
{
public interface ISocket : IDisposable
{
int BufferSize { get; }
bool Connected { get; }
using System.Net;
using System.Net.Sockets;
namespace XGain.Sockets
{
internal class XGainSocket : ISocket
{
public int BufferSize => 65535;
public bool Connected => _socket.Connected;
public Socket InternalSocket => _socket;