tcpclient

How do i send an email when i already have it as a string?

蹲街弑〆低调 提交于 2019-12-05 21:17:09
Effectively I'm trying to send some template emails so that I can test a few components that handle reading from mailboxes. I could just load up outlook and send a couple of emails but I'm looking to find a solution that can read thousands of emails at a time so I need to bulk send these templates t test the reading code. When I say bulk send ... I have about 10 to 15 templates (varies) and I want to send about 1,000 copies of each to the given mailbox. Now here's th sticking point ... I could just fire up an instance of the SMTP client and declare a new MailMessage object then send that using

How to get page via TcpClient?

亡梦爱人 提交于 2019-12-05 17:33:21
I'm trying to send a GET request to a page via TCP stream. Here's what my code looks like: public class SocketLevelWebClient { public string SendWebRequest(string url, string request) { using(TcpClient tc = new TcpClient()) { tc.Connect(url, 80); using (NetworkStream ns = tc.GetStream()) { using (System.IO.StreamWriter sw = new System.IO.StreamWriter(ns)) { using (System.IO.StreamReader sr = new System.IO.StreamReader(ns)) { sw.Write(request); sw.Flush(); return sr.ReadToEnd(); } } } } } And the request itself: SocketLevelWebClient wc = new SocketLevelWebClient(); var r=wc.SendWebRequest("www

Why does Java read random amounts from a socket but not the whole message?

爱⌒轻易说出口 提交于 2019-12-05 13:26:42
I am working on a project and have a question about Java sockets. The source file which can be found here . After successfully transmitting the file size in plain text I need to transfer binary data. (DVD .Vob files) I have a loop such as // Read this files size long fileSize = Integer.parseInt(in.readLine()); // Read the block size they are going to use int blockSize = Integer.parseInt(in.readLine()); byte[] buffer = new byte[blockSize]; // Bytes "red" long bytesRead = 0; int read = 0; while(bytesRead < fileSize){ System.out.println("received " + bytesRead + " bytes" + " of " + fileSize + "

c# NetworkStream write() and read()

拜拜、爱过 提交于 2019-12-05 12:33:55
I'm wondering how to stop Networkstream.Read() from blocking thread. I have separate thread where NetworkStream.Read() is waiting for data from server. Assume that user press some button that send some data to server. But I can't call NetworkStream.Write() while there is NetworkStream.Read() in other thread waiting for data. I can lock NetworkStream each time but NetworkStream.Read() will block thread so I can't send data until read at least 1 byte. Bjorn Coltof You can issue both read and write simultaneously as stated in the docs at MSDN docs Read and write operations can be performed

Configure socket ACK timeout?

蹲街弑〆低调 提交于 2019-12-05 11:46:33
问题 Is there a way to configure the timeout in which a socket expects to receive an ACK for sent data before it decides that the connection has failed? I'm aware this can be done at the application level as well, but since every packet I send is ACK'd anyway, and I just want to know if my data is received, using additional data at the application level to accomplish the same thing seems wasteful. (Not to mention, my particular application uses per-byte charged cellular links.) Note: As per my

When sending data larger than the SendBufferSize, how will the data be received?

佐手、 提交于 2019-12-05 08:54:28
问题 I just asked a question on how to send data larger than the SendBufferSize and the answer was that is would be send in a couple of parts. My second question is how will this data be received? Will it be complete in the network stream or will it get it divided. the first question: Can you send a file larger that the SendBufferSize throuh a TcpClient? 回答1: TCP is not a message only protocol. It is a stream based protocol and takes care of splitting the data for us. Lemme take you to the core

Cancel C# 4.5 TcpClient ReadAsync by timeout

◇◆丶佛笑我妖孽 提交于 2019-12-05 08:31:49
What would the proper way to cancel TcpClient ReadAsync operation by timeout and catch this timeout event in .NET 4.5? TcpClient.ReadTimeout seems to be applied to the sync Read only. UPDATE: Tried tro apply the approach desribed here Cancelling an Asynchronous Operation var buffer = new byte[4096]; CancellationTokenSource cts = new CancellationTokenSource(5000); int amountRead = await tcpClientStream.ReadAsync(buffer, 0, 4096, cts.Token); but it never cancels by timeout. Is anything wrong? so I know that was from a long time but google still drive me here and I saw there is none marked as

Unable to connect from remote machine

孤街浪徒 提交于 2019-12-05 03:04:05
I have some kind of problem and I can't check this at home if its working or not. Here is the code using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using System.Net.Security; class Program { private static IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); private static int port = 6000; private static string data = null; static void Main(string[] args) { Thread thread = new Thread(new ThreadStart(receiveThread)); thread.Start(); Console.ReadKey(); } public static void receiveThread() { while (true) { TcpListener tcpListener = new TcpListener

Change background color has no effect once screen has been rotated

拥有回忆 提交于 2019-12-04 21:50:24
all I am new to Android and now I am facing a strange problem, the problem in short is "Receive TCP message and then change background color of GUI has no effect once screen has been rotated." What I want to archive: Have a APP running on Android device, connect to a PC via TCP. PC can send a string to APP, the APP will then do something base on string received. In this case a string, "change back ground color to red(with phone vibrates)/black" is send to APP via TCP, so Android user will see a blinding effect with vibration. What is the problem: I can archive what I want. But once the screen

Bypass the proxy using TcpClient

旧城冷巷雨未停 提交于 2019-12-04 21:09:07
I'm trying to write a local proxy application. I know how proxy applications work in theory. I've done everything related to handle incoming connections. But the problem is how should I send request which client requested to specified Url. When I try to create a connection with TcpClient to specified Url and port, it throws following exception : No such host is known Edit : I think I should bypass the proxy something like FireFox is doing even system proxy set. Any idea will be helpful. Thanks in advance. Colin Smith These links might be of help: http://www.replicator.org/journal/201011170043