Skip to content

Commit

Permalink
TCP: prototype of the chat's basis
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Apr 19, 2018
1 parent 38fc01c commit d9436a0
Show file tree
Hide file tree
Showing 17 changed files with 902 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
/GKSimpleChat/obj/
/GKSimpleChat/temp/

/DHT/bin/
/DHT/obj/

/DHTSample/bin/
/DHTSample/obj/

/TCPChatTest/bin/
/TCPChatTest/obj/

/temp/

testrun_git.mswin.cmd
6 changes: 6 additions & 0 deletions GKConnectivity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GKNetPNRP", "GKNetPNRP\GKNe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DHTSample", "DHTSample\DHTSample.csproj", "{E19B390E-BA4C-4333-A4C1-2C390B1C1930}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TCPChatTest", "TCPChatTest\TCPChatTest.csproj", "{F0D4D14C-0635-4965-9EC4-8CFE5265CD17}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{E19B390E-BA4C-4333-A4C1-2C390B1C1930}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E19B390E-BA4C-4333-A4C1-2C390B1C1930}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E19B390E-BA4C-4333-A4C1-2C390B1C1930}.Release|Any CPU.Build.0 = Release|Any CPU
{F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0D4D14C-0635-4965-9EC4-8CFE5265CD17}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 27 additions & 0 deletions TCPChatTest/DataReceiveEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Net;

namespace TCPChatTest
{
public class DataReceiveEventArgs : EventArgs
{
private byte[] fData;
private IPEndPoint fPeer;

public DataReceiveEventArgs(byte[] data, IPEndPoint peer)
{
fData = data;
fPeer = peer;
}

public IPEndPoint Peer
{
get { return fPeer; }
}

public byte[] Data
{
get { return fData; }
}
}
}
170 changes: 170 additions & 0 deletions TCPChatTest/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions TCPChatTest/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace TCPChatTest
{
public partial class Form1 : Form
{
private TCPDuplexClient fClient;

public Form1()
{
InitializeComponent();
}

private void btnConnect_Click(object sender, EventArgs e)
{
fClient = new TCPDuplexClient();
fClient.DataReceive += RaiseDataReceive;
fClient.Start(int.Parse(txtLocalPort.Text));

txtLocalPort.Enabled = false;
btnConnect.Enabled = false;
}

private void btnSend_Click(object sender, EventArgs e)
{
var endPoint = new IPEndPoint(IPAddress.Parse(txtRemoteAddress.Text), int.Parse(txtRemotePort.Text));
fClient.Send(endPoint, txtMsg.Text);
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
//fServer.Disconnect();
}

public void RaiseDataReceive(object sender, DataReceiveEventArgs e)
{
Invoke((MethodInvoker)delegate {
txtLog.Text += Encoding.UTF8.GetString(e.Data) + "\r\n";
});
}
}
}
Loading

0 comments on commit d9436a0

Please sign in to comment.