Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Sockets;
- using System.Net;
- using System.IO;
- namespace ClientSocket
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- TcpClient tcpclnt = new TcpClient();
- //Console.WriteLine("Connecting.....");
- int PORT = 8888;
- string IP = "127.0.0.1";
- for (int i = 0; i < args.Length; i++)
- {
- string[] arg = args[i].Split(':');
- string a = arg[0].Replace("\"", "").Trim();
- string b = arg[1].Replace("\"", "").Trim();
- switch (a)
- {
- case "-i":
- IP = b;
- break;
- case "-p":
- int.TryParse(b, out PORT);
- break;
- default:
- break;
- }
- }
- tcpclnt.Connect(IP, PORT);
- // use the ipaddress as in the server program
- //Console.WriteLine("Connected");
- String str = "getData";
- Stream stm = tcpclnt.GetStream();
- ASCIIEncoding asen = new ASCIIEncoding();
- byte[] ba = asen.GetBytes(str);
- //Console.WriteLine("Transmitting.....");
- stm.Write(ba, 0, ba.Length);
- byte[] bb = new byte[100];
- int k = stm.Read(bb, 0, 100);
- for (int i = 0; i < k; i++)
- Console.Write(Convert.ToChar(bb[i]));
- tcpclnt.Close();
- Environment.Exit(0);
- }
- catch (Exception e)
- {
- // Console.WriteLine("Error..... " + e.StackTrace);
- Environment.Exit(1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement