本文整理汇总了C#中System.Net.Sockets.TcpClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Sockets.TcpClient.Connect方法的具体用法?C# System.Net.Sockets.TcpClient.Connect怎么用?C# System.Net.Sockets.TcpClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpClient
的用法示例。
在下文中一共展示了System.Net.Sockets.TcpClient.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectionTask
void ConnectionTask()
{
try
{
IsInConnectionTask=true;
while (true)
{
client = new System.Net.Sockets.TcpClient();
try
{
Console.WriteLine("try to connect " + ip + ":" + port + " !");
client.Connect(ip, port);
Console.WriteLine(ip + ":" + port + "connected! ");
}
catch (Exception ex)
{
Console.WriteLine(ip + ":" + port + " " + ex.Message);
}
if (client.Connected)
{
new System.Threading.Thread(ReceiveTask).Start();
return;
}
}
}
catch { ;}
finally
{
IsInConnectionTask = false;
}
}
示例2: TryPrint
public void TryPrint(string zplCommands)
{
try
{
// Open connection
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect(this.m_IPAddress, this.m_Port);
// Write ZPL String to connection
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
writer.Write(zplCommands);
writer.Flush();
// Close Connection
writer.Close();
client.Close();
}
catch (Exception ex)
{
this.m_ErrorCount += 1;
if(this.m_ErrorCount < 10)
{
System.Threading.Thread.Sleep(5000);
this.TryPrint(zplCommands);
}
else
{
throw ex;
}
}
}
示例3: Connect
private static bool Connect(string friendly)
{
try
{
client = new System.Net.Sockets.TcpClient();
TVServer.MPClient.Client mpclient = uWiMP.TVServer.MPClientDatabase.GetClient(friendly);
if (mpclient.Hostname == string.Empty)
{
host = friendly;
}
else
{
host = mpclient.Hostname;
}
if (mpclient.Port == string.Empty)
{
port = DEFAULT_PORT;
}
else
{
port = Convert.ToInt32(mpclient.Port);
}
client.Connect(host, port);
}
catch (Exception ex)
{
return false;
}
return true;
}
示例4: connect
public static string connect(String server,int port,String ouath)
{
System.Net.Sockets.TcpClient sock = new System.Net.Sockets.TcpClient ();
sock.Connect (server, port);
if (!sock.Connected) {
Console.Write ("not working hoe");
}
System.IO.TextWriter output;
System.IO.TextReader input;
output = new System.IO.StreamWriter (sock.GetStream ());
input = new System.IO.StreamReader (sock.GetStream ());
output.Write (
"PASS " + ouath + "\r\n" +
"NICK " + "Sail338" + "\r\n" +
"USER " + "Sail338" + "\r\n" +
"JOIN " + "#sail338" + "" + "\r\n"
);
output.Flush ();
for (String rep = input.ReadLine ();; rep = input.ReadLine ()) {
string[] splitted = rep.Split (':');
if (splitted.Length > 2) {
string potentialVote = splitted [2];
if (Array.Exists (validVotes, vote => vote.Equals(potentialVote)))
return potentialVote;
}
}
}
示例5: Create
public static OpcWriter Create(IPEndPoint target)
{
var client = new System.Net.Sockets.TcpClient();
client.Connect(target.Address, target.Port);
var stream = client.GetStream();
return new OpcWriter(stream, true);
}
示例6: printButton_Click
private void printButton_Click(object sender, EventArgs e)
{
// Printer IP Address and communication port
string ipAddress = printerIpText.Text;
int port = 9100;
try
{
// Open connection
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect(ipAddress, port);
// Write ZPL String to connection
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
writer.Write(zplCode);
writer.Flush();
// Close Connection
writer.Close();
client.Close();
MessageBox.Show("Print Successful!", "Success");
this.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex);
MessageBox.Show("No printer installed corresponds to the IP address given", "No response");
}
}
示例7: Start
public bool Start()
{
System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse(this.ipString);
if (objSck != null)
{
objSck.Close();
objSck = null;
}
objSck = new System.Net.Sockets.TcpClient();
try
{
objSck.Connect(ipAdd, port);
}
catch(Exception)
{
return false;
}
//catch (Exception)
//{
// throw;
//}
//NetworkStreamを取得
ns = objSck.GetStream();
return true;
}
示例8: Main
static void Main(string[] args)
{
CreateServerCode();
return;
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect("210.245.121.245", 4530);
Console.WriteLine("Ok");
}
示例9: connectClient
public void connectClient(string ip, int port)
{
myip = ip;
myport = port;
xclient = new System.Net.Sockets.TcpClient();
System.Net.IPAddress addr = System.Net.IPAddress.Parse(ip);
xclient.Connect(new System.Net.IPEndPoint(addr, port));
}
示例10: Con
public System.Net.Sockets.TcpClient Con(int port, string nick, string server, string chan)
{
//Connect to irc server and get input and output text streams from TcpClient.
System.Net.Sockets.TcpClient sock = new System.Net.Sockets.TcpClient();
sock.Connect(server, port);
if (!sock.Connected)
{
Console.WriteLine("Failed to connect!");
}
return sock;
}
示例11: PerformWhois
public static string PerformWhois(string WhoisServerHost, int WhoisServerPort, string Host)
{
string result="";
try {
String strDomain = Host;
char[] chSplit = {'.'};
string[] arrDomain = strDomain.Split(chSplit);
// There may only be exactly one domain name and one suffix
if (arrDomain.Length != 2) {
return "";
}
// The suffix may only be 2 or 3 characters long
int nLength = arrDomain[1].Length;
if (nLength != 2 && nLength != 3) {
return "";
}
System.Collections.Hashtable table = new System.Collections.Hashtable();
table.Add("de", "whois.denic.de");
table.Add("be", "whois.dns.be");
table.Add("gov", "whois.nic.gov");
table.Add("mil", "whois.nic.mil");
String strServer = WhoisServerHost;
if (table.ContainsKey(arrDomain[1])) {
strServer = table[arrDomain[1]].ToString();
}
else if (nLength == 2) {
// 2-letter TLD's always default to RIPE in Europe
strServer = "whois.ripe.net";
}
System.Net.Sockets.TcpClient tcpc = new System.Net.Sockets.TcpClient ();
tcpc.Connect(strServer, WhoisServerPort);
String strDomain1 = Host+"\r\n";
Byte[] arrDomain1 = System.Text.Encoding.ASCII.GetBytes(strDomain1.ToCharArray());
System.IO.Stream s = tcpc.GetStream();
s.Write(arrDomain1, 0, strDomain1.Length);
System.IO.StreamReader sr = new System.IO.StreamReader(tcpc.GetStream(), System.Text.Encoding.ASCII);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
string strLine = null;
while (null != (strLine = sr.ReadLine())) {
strBuilder.Append(strLine+"\r\n");
}
result = strBuilder.ToString();
tcpc.Close();
}catch(Exception exc) {
result="Could not connect to WHOIS server!\r\n"+exc.ToString();
}
return result;
}
示例12: SendBytes
private void SendBytes(IPEndPoint endpoint, byte[] buffer)
{
using (var client = new System.Net.Sockets.TcpClient())
{
client.Connect(endpoint);
var stream = client.GetStream();
stream.Write(buffer, 0, buffer.Length);
stream.Flush();
client.Close();
}
}
示例13: getSocket
private System.Net.Sockets.TcpClient getSocket(String theAddress, int port)
{
System.Net.Sockets.TcpClient s = new System.Net.Sockets.TcpClient();
try
{
s.Connect(theAddress, port);
}
catch (System.IO.IOException e)
{
throw new NuGenTransportException(e);
}
return s;
}
示例14: _main
static void _main()
{
BlackCore.basic.cParams args = bcore.app.args;
client = new System.Net.Sockets.TcpClient();
int wavInDevices = WaveIn.DeviceCount;
int selWav = 0;
for (int wavDevice = 0; wavDevice < wavInDevices; wavDevice++)
{
WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(wavDevice);
Console.WriteLine("Device {0}: {1}, {2} channels", wavDevice, deviceInfo.ProductName, deviceInfo.Channels);
}
Console.Write("Select device: ");
selWav = int.Parse(Console.ReadLine());
Console.WriteLine("Selected device is " + selWav.ToString());
sshClient = new SshClient(args["host"], args["user"], args["pass"]);
sshClient.Connect();
if (sshClient.IsConnected)
{
shell = sshClient.CreateShellStream("xterm", 50, 50, 640, 480, 17640);
Console.WriteLine("Open listening socket...");
shell.WriteLine("nc -l " + args["port"] + "|pacat --playback");
System.Threading.Thread.Sleep(2000);
Console.WriteLine("Try to connect...");
client.Connect(args["host"], int.Parse(args["port"]));
if (!client.Connected) return;
upStream = client.GetStream();
//====================
WaveInEvent wavInStream = new WaveInEvent();
wavInStream.DataAvailable += new EventHandler<WaveInEventArgs>(wavInStream_DataAvailable);
wavInStream.DeviceNumber = selWav;
wavInStream.WaveFormat = new WaveFormat(44100, 16, 2);
wavInStream.StartRecording();
Console.WriteLine("Working.....");
Console.ReadKey();
sshClient.Disconnect();
client.Close();
wavInStream.StopRecording();
wavInStream.Dispose();
wavInStream = null;
}
}
示例15: Test
//public ActionResult ListUpnp()
//{
// var upnp = new NATUPNPLib.UPnPNATClass();
// if (upnp.StaticPortMappingCollection == null) return Content("UPnP Disabled");
// var result = upnp.StaticPortMappingCollection.Cast<NATUPNPLib.IStaticPortMapping>()
// .Aggregate("", (s, m) => s + m.Description + "<br/>");
// return Content(result);
//}
//public ActionResult EnableUpnp()
//{
// var upnp = new NATUPNPLib.UPnPNATClass();
// if (upnp.StaticPortMappingCollection == null) return Content("UPnP Disabled");
// var localIP = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())
// .First(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
// upnp.StaticPortMappingCollection.Add(25565, "TCP", 25565, localIP.ToString(), true, "Minecraft");
// return Redirect("/Home/ListUpnp");
//}
//public ActionResult DisableUpnp()
//{
// var upnp = new NATUPNPLib.UPnPNATClass();
// if (upnp.StaticPortMappingCollection == null) return Content("UPnP Disabled");
// upnp.StaticPortMappingCollection.Remove(25565, "TCP");
// return Redirect("/Home/ListUpnp");
//}
public ActionResult Test()
{
var client = new System.Net.Sockets.TcpClient();
try
{
client.Connect("localhost", 25565);
client.Close();
return Content("Connection OK " + DateTime.Now.Ticks);
}
catch (Exception e)
{
return Content("Error:<br />" + e.Message);
}
}