-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38fc01c
commit d9436a0
Showing
17 changed files
with
902 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.