-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_bigfile.cs
More file actions
51 lines (37 loc) · 1.51 KB
/
client_bigfile.cs
File metadata and controls
51 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
public partial class Form1 : Form
{
string m_splitter = "'\\'";
string m_fName;
string[] m_split = null;
byte[] m_clientData;
public Form1()
{
InitializeComponent();
}
private void sendButton_Click(object sender, EventArgs e)
{
char[] delimiter = m_splitter.ToCharArray();
// Show the open file dialog to select our data.
openFileDialog1.ShowDialog();
//Get the file name and write it into our text box.
textBox1.Text = openFileDialog1.FileName;
m_split = textBox1.Text.m_split(delimiter);
int limit = m_split.Length;
m_fName = m_split[limit - 1].ToString();
if (textBox1.Text != null) button1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
byte[] fileName = Encoding.UTF8.GetBytes(m_fName); //file name
byte[] fileData = File.ReadAllBytes(textBox1.Text); //file
byte[] fileNameLen = BitConverter.GetBytes(fileName.Length); //lenght of file name
m_clientData = new byte[4 + fileName.Length + fileData.Length];
fileNameLen.CopyTo(m_clientData, 0);
fileName.CopyTo(m_clientData, 4);
fileData.CopyTo(m_clientData, 4 + fileName.Length);
clientSock.Connect("192.168.2.10", 9050); //target machine's ip address and the port number
clientSock.Send(m_clientData);
clientSock.Close();
}
}