tcpclient

Reconnect to the server

若如初见. 提交于 2019-12-12 02:53:38
问题 My Tcpclient did not disconnect properly I am using Client async. I want to reconnect again automatic when server disconnect. What is correct path? This is Connection code private void Connect_btn_Click(object sender, EventArgs e) { try { if (IsConnected == false) { constatus.Text = "Connecting....."; newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //IPEndPoint iep = new IPEndPoint(IPAddress.Any, 20); IPEndPoint iep = new IPEndPoint(IPAddress.Parse(IP),

TCPClient. How do I receive big messages?

我的梦境 提交于 2019-12-12 02:48:16
问题 I have the following code: private string Connect() { string responseData; try { TcpClient client = new TcpClient(ServerIp, Port); client.ReceiveBufferSize = Int32.MaxValue; Byte[] data = Encoding.GetEncoding(1251).GetBytes(ReadyQuery); NetworkStream stream = client.GetStream(); // send data stream.Write(data, 0, data.Length); // buffer data = new Byte[65536]; Int32 bytes = stream.Read(data, 0, data.Length); responseData = Encoding.GetEncoding(1251).GetString(data, 0, bytes); // close all

TCP Server gets ???????? instead of the real message

烈酒焚心 提交于 2019-12-12 02:34:35
问题 The server is written in c# and works correctly with a client I made in c#, now i'm trying to make an android client but the server doesn't get the real message, it gets just a lot of question marks. Here is the server TcpListener listen = new TcpListener(IPAddress.Any, 1200); TcpClient client; listen.Start(); client = listen.AcceptTcpClient(); NetworkStream stream = client.GetStream(); byte[] buffer = new byte[client.ReceiveBufferSize]; int data = stream.Read(buffer, 0, client

Why is my TCP connection closing?

折月煮酒 提交于 2019-12-12 02:32:40
问题 I have developed an application for my game server. Now, in this application when I press "Connect" it sends data to my Game Server. And it does, but, the problem is, when it sends the connection it automatically closes it, and I don't want to close it because I have a socket plugin that kills the TCP connection after player leaves the game. Now on my localhost it works, the TCP doesn't "die" but on my vps it disconnects, can someone please check my code and see if I'm doing something wrong?

Stream from TCPClient catching data from next packet

ⅰ亾dé卋堺 提交于 2019-12-12 01:47:15
问题 I'm developing some software that listens for events from another program via TCP. The events come in a string formatted like this: "value1;value2;value3" The problem is that sometimes a single character from value1 gets read onto the previous event so i get something like this: value1;value2;value3v alue1;value2;value3 How can i make it know where each message begins and ends? Here is the code: Dim client As New TcpClient() Sub listen() Dim networkStream As Stream = client.GetStream() While

Do I have to create a new TcpClient for each message I send?

佐手、 提交于 2019-12-12 01:38:23
问题 I remain frustrated in my attempts to send multiple TCP messages. I do not know what I have to do on the client side. I've tried using a Socket object and a TcpClient object. I can send one message with no problem. But what do I have to do to send a second message? Do I have to just discard the socket or TcpClient and create a new one? I've never yet been able to to get a second message to work. Here is my latest attempt with TcpClient. It sends one message and displays the response

Create an empty stream from a string on which Stream.Read() waits when no data

雨燕双飞 提交于 2019-12-12 01:25:12
问题 I am trying to replace the stream i get from TcpClient.GetStream() by a stream I create from a string. I am using the following method to create said Stream: public Stream GenerateStreamFromString(string s) { MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(s); writer.Flush(); stream.Position = 0; return stream; } However this stream is read by using Stream.Read() somewhere in a library i do not WANT to change. The problem is I create this

C# while remote TCP connection

北战南征 提交于 2019-12-12 01:16:55
问题 I am trying to have a server allow TCP connections and and echo out any newline delimited messages being sent. I want multiple clients to be able to connect one after another, maintaining the same server socket. Here's my code: TcpClient client; while (true) { Console.Write("Waiting for connection... "); client = listener.AcceptTcpListener(); nStream = client.GetStream(); sReader = new StreamReader(nStream); Console.WriteLine("Connected!"); while (client.Connected) { string line = sReader

Why is my proxy unusably slow?

社会主义新天地 提交于 2019-12-12 01:14:55
问题 Its less <130 lines. Nothing about it is complex. Why is this code so slow that my proxy is unusable? It takes seconds to hit a webpage and it gets worse after hitting 2/3 domains. The CPU is also through the roof which confuses me. Also I can't get above 350kb a second downloading a large file (i tested by downloading linux iso, one that i get >350 w/o the proxy) using System; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net.Sockets; using System.IO; using

RecieveBufferSize OutOfRangeException (.NET)

天涯浪子 提交于 2019-12-11 23:19:31
问题 (Before I start I know this title is awful if someone could think of a better name I'd love it) I ran out of ideas to program, and found a post listing some things, so I made a simple local chat server. The server runs fine until I attempt to connect (via tcpClient) The code from the client side is as follows: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click readData = "Connected." Msg() clientSocket.Connect("xxx.xxx.xx.xxx", 8888) serverStream = clientSocket