Click here to Skip to main content
15,888,092 members
Everything / TCP/IP

TCP/IP

TCP/IP

Great Reads

by Espen Harlinn
A .NET Core client implemented in C# using TcpClient and a multi-threaded server implemented in C++
by pdoxtader
Learn how to view a remote machine's file system using your own explorer like window, and transfer files and folders by dragging and dropping in C# using the TcpComm TCP library
by bkelly13
Goal: Describe how asynchronous or non-blocking TCP code works
by Dan Randolph
Builds on the existing RunRemote project to run commands on a remote server.

Latest Articles

by Patrick Eckler
Example of a TCPIP server that listens and can serve multiple client connections
by Mirzakhmet Syzdykov
Network programming in C++
by Espen Harlinn
A .NET Core client implemented in C# using TcpClient and a multi-threaded server implemented in C++

All Articles

Sort by Title

TCP/IP 

9 May 2014 by Dimitri Nostarik
Hello Codeproject,I'm looking to create a secure connection between a server and a client. The client will be sending valuable information, and because it's valuable I wish to secure the information transferred from one another.A type of security that does what I mean is SSL. Basically...
9 May 2014 by Rob Philpott
Sounds like SSL is what you want. It does two things for you, encrypts the data sent back and forth so it can't (allegedly) be any use to anyone eavesdropping but it also confirms the server is the real server and not some imposter.SSL exchanges a symmetric key using asymmetric encryption -...
3 Aug 2010 by ankitpsaraogi
This is the form.cs in my REMOTE SERVERusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels;using...
3 Aug 2010 by William Winner
have you adjusted the firewall on the target machine to allow incoming traffic on that port?It's nothing to do with your code, but everything to do with the machine that you're using to hose the object on.
4 Aug 2010 by ankitpsaraogi
Yes I have even tried turning off the firewall...Are my codes correct???
10 Aug 2010 by John Whitmire
The code you posted shows escape sequences in your strings that will give you unexpected results, but I suspect that was just a posting oversight. If not, start there.You won't get any connection over the Internet with the address you posted since that is a non-routable address that won't...
24 Mar 2017 by User 13050660
Hi,I'm making a TCP Server/Client chat program. I have two clients. The problem I'm having is that I can send one message from one of the clients, but then consecutive messages from the same client get sent to the server, but the server doesn't pass them on until I send a message from the...
27 Oct 2013 by kleymanx90
hi,i have two packet Classes ,1- CommandPacket: class CommandPacket { /** @var CommandPacketHeader */ private $header; private $data;}and 2- CommandPacketHeader :class CommandPacketHeader { /** @var integer Cardinal */ private...
27 Oct 2013 by Richard MacCutchan
You already posted this at http://www.codeproject.com/Messages/4688029/how-can-i-split-an-object-into-chunks-and-send-the.aspx[^]. Please read the guidelines and use one forum only.
2 May 2013 by evanharijanto
Hi all, I'd like to ask a question.I would like to receive a data from an UDP port and display the data as string.here is my trial code, but it doesn't works.it is stated in the error message that it can't bind and also stated socket.bind(native method)I am still don't understand...
2 May 2013 by AlphaDeltaTheta
Well, your code is absolutely correct there is no issues with it.You are encountering a bind exception. Such exceptions occur if the underlying operating system is unable to create an socket at the specified port. It might be for the following reasons:1. The port 53 is already in use. In...
2 May 2013 by AlphaDeltaTheta
Well, your has no issues with it. Except for the thing that the constructor used to create a datagram socket for receiving must not include the ip address. It should be like thisDatagramPacket p = new DatagramPacket(buffer, buffer.length);You are encountering a bind exception. Such...
2 May 2013 by evanharijanto
solved!! thanks everyone!!here is the code I have made after some confusing period.import java.io.IOException;import java.net.DatagramPacket;import java.net.DatagramSocket;import java.net.InetAddress;import java.net.SocketException;public class udp_test{ public static void...
17 May 2012 by Ahmed Charfeddine
A Websocket protocol implementation atop the ush Framework real time library plus a demo example featuring four types of communication workflows between the HTML5 web client and the server.
23 Feb 2014 by Sacha Barber
A small article on how to use NServiceBus to create workflows
1 Jun 2011 by SimpleData
Hi,I am trying to send a big file over a TCP connection using NetworkStream and TCPClient. Both the client and the server is written in C#.There is no problem while transferring small files around the size of 300KB. My buffer size is 2KB and here is how the protocol works.-Server...
1 Jun 2011 by Sergey Alexandrovich Kryukov
If you really want to keep to pure client-server paradigm, server cannot request anything. Server is purely passive. If you want to implement some inversion of control, it's fine but don't call it client and server. You application does not need it.— Client: I'm sending a file: name is...
11 Dec 2008 by spinoza
This source code uses the advanced IOCP technology which can efficiently serve multiple clients. It also presents some solutions to practical problems that arise with the IOCP programming API, and provides a simple echo client/server with file transfer.
16 Apr 2022 by Ehliz Brothers
(i) What is the length of the header? (ii)What is the address of the source port? (iii)What is the address of the destination port? (iv)What is the sequence number? (v) What is the acknowledgement number? What I have tried: I have looked at...
16 Apr 2022 by Richard MacCutchan
You need to study the format of a TCP packet: Transmission Control Protocol - Wikipedia[^]. And maybe also an IPv4 packet: IPv4 - Wikipedia[^].
23 Jun 2020 by Greg Utas
Replacing its erase() function
1 Dec 2010 by Alexeirob
Hi,I'm having a problem with accept function in Windows.It takes 2-4 seconds to accept a socket from another 3rd party application.Here is my code:DWORD dwStart = GetTickCount();AcceptSocket = accept(ListenSocket, NULL, NULL);DWORD dwEnd = GetTickCount();DWORD time = dwEnd -...
1 Dec 2010 by E.F. Nijboer
Have a look at the remarks on accept:The accept function can block the caller until a connection is present if no pending connections are present on the queue, and the socket is marked as blocking. If the socket is marked as nonblocking and no pending connections are present on the queue,...
13 May 2015 by Member 11687571
Good day dear programmers , hopefully soon I become a colleague :) . I am just new to programming , but still I have had some experience with programming in Access VB and a a small overview over VB.Net . But let's get to the question . I want to build a nice app with a Server side and...
13 May 2015 by Afzaal Ahmad Zeeshan
A Windows Forms application would be good, but since you're going to allow multiple users to communicate through the same hub (server), ASP.NET would be better. If you do not want to use a website, with a layout and other formalities, ASP.NET Web API[^] would be best for this type of...
8 Sep 2020 by Patrice T
Quote: 1. What is the sequence number? 2. What is the destination port number? 3. What is the source port number? 4. What is the length of the TCP header? 5. What is the acknowledgement number? What about doing basic research on internet before...
30 Jan 2014 by RAHUL(10217975)
I am working on WPF Application. It is connected to Android App via TCP/IP. Now,the requirement is Employee should able to pause /disable the current WPF.xaml from android.(As Employee may go far from application .So, no other person should access the main application). I tried ...
31 Jan 2014 by mostwanted4
I can think of a couple of solutions: 1.Probably the easiest solution is to place a rectangle or whatever on top of everything else so that people can't click anything. 2.If you also want to prevent people from easily closing the app you can minimize it to tray and then wait...
9 Feb 2019 by zvx
An introduction to writing IOCP network servers
16 May 2014 by Member 10824754
is required to produce a system by using Java language.The system should have the following function:1. The system must use be a client/server based application. 2. The system must have a database to store data.3. The system must consist of at least 3 modules are:a. ...
16 May 2014 by Mehdi Gholam
This forum is for helping people who help themselves and have a genuine problem, not for people who are not willing to do work.
30 Nov 2013 by Morbiddeath
I have a structure to represent the ARP (address resolution protocol) but the bytes in memory are misaligned, its a 64 bit capable processor running 32 bit OS.The structure is 28 byte and is as follows:ARP structure: unsigned short hardware; //could use USHORT but like it...
30 Nov 2013 by OriginalGriff
Data alignment is the simple answer.A char is a single byte, so it can be aligned on an odd or an even byte boundary - the address of the character can be odd or even.Generally speaking any datatype which is not byte long needs to be aligned on an even address (or longer depending on the...
11 Dec 2013 by Member 10440446
Hi guys, any idea on how am I suppose to create an application on C# 5.0 using async await Telnet client.My scenario is that I have to telnet multiple servers at the same time. Also, i need it to check the servers continuously just like a ping /t function.Thanks much.. :)
12 Dec 2013 by Sergey Alexandrovich Kryukov
Why?! Create a separate thread to work with each separate telnet server and work synchronously. Synchronize those threads using thread synchronization in those rare cases when it is needed.I think asynchronous APIs get popularity when threads were not a commonplace, or just because many...
15 Jul 2014 by Matthew Dennis
// assuming you have created a CancellationToken so you can cancel the Telnet Monitors.List telnetTasks = new List();for (var i = 0; i
3 Jun 2011 by tarunkashyap p
hi, I from electrical engineering and i know very little about programming.can you help me with developing an application for single server multiple client(few hundreds) communication(TCP/IP protocol), which has to be asynchronous and server capable of replying to the data requested by the...
3 Jun 2011 by Tarakeshwar Reddy
What have you tried till now? Try to apply what ever knowledge you have gained from reading the articles you mentioned. Code project has a lot of articles on the topics you have mentioned. Give it a try and ask specific questions, people would be more than willing to help when they see your effort.
3 Jun 2011 by tarunkashyap p
Thank you very much for responding to my post. I have written a code base on some articles and i am able to connect to the server from multiple clients. My client application is a windows form application and server is a console application. After connecting to few clients and try to send...
6 Jun 2011 by tarunkashyap p
Server program (Console application)using System;using System.Threading;using System.Net.Sockets;using System.Text;using System.Net;using System.IO;namespace ConsoleApplication{ class Program { public Socket socketStream; private BinaryWriter...
14 Sep 2018 by bkelly13
Goal: Describe how asynchronous or non-blocking TCP code works
20 Dec 2015 by venkat28vk
Hi,I have developed a server and client code using tcp/ip protocol, which enables the client to send data to server and the same data is received from server to client. I would like to know how to keep the client open all the time, same like as server. I should not keep executing the...
18 Dec 2015 by Garth J Lancaster
surely that depends on YOU - what you you want/need to achieve in the client ? (we dont know your requirements because you havnt stated any)instead of str_echo(ls); you could do for (; ; ){ str_echo(ls); sleep(60 * 1000); // for example to sleep 1 minute between loops...
9 Nov 2022 by Деян Цонев
Hello. I am trying to implement tcp server and client. My client close connection after every data transfer. When I run my server against my client there is no problem, but when trying to run against netcat it blocks on accept(). Where is my...
9 Nov 2022 by k5054
Your tcp_server_send_packet() function builds and tears down a connection for every "heartbeat" packet. That might not be what you intend. netcat does not timeout a closed connection, but you can get it to do so by adding an idle timeout e.g nc...
30 Jan 2019 by Member 13325846
Hi, I am going to learn about how to map a BUS System (WAGO 750-342) and how to read sensors data from them and to show pulse of each sensor in a textbox. i have knowledge about TCP/IP but i have no knowledge about how can i map which module is incremental, Analog or digital and read their...
30 Jan 2019 by RickZeeland
See this ModBus library: GitHub - NModbus4/NModbus4: NModbus4 is a C# implementation of the Modbus protocol.[^] And: EasymodbusTCP Modbus Library for .NET/Java and Python – Communication library and professional tools for industrial communication[^] Also see: Wago I/O 750-370 communication[^]
27 May 2020 by Demuter
I tried to poll the device using the Modbus protocol for TCP/IP, and it works well, but there are problems. If I run this code on a weak computer, the response time will increase and very much... The difference in polling speed is about 6...
27 May 2020 by Gerry Schmitz
You keep opening a new connection every time you make a request; that's where all your "lag" is. You create a connection to a device, and keep it open while you are "sending and receiving." You close the connection when you're "done".
15 Oct 2010 by shynet
Allow multiple users to send and receive messages from one another on the same server
21 Sep 2017 by Member 3844375
I am new to TCP and I am trying to connect to a machine. I've been given the command to connect to the machine. which is in the form of xml. The port and IP to the machine is also provided, all i have to do is send the command. The documentation stipulates TCP/IP channels are required for...
21 Sep 2017 by RickZeeland
Here is a simple Client - Server example: Introduction to TCP client server in C#[^] Note that you will have to allow your program through Windows firewall. If you need authentication, see this example: Authenticate WebAPIs with Basic and Windows Authentication[^]
4 Aug 2019 by Leonid Kazakov
I create a list of connections using TcpConnectionInformation, after it I find in that list the address which used in my program by the external IP RemoteEndPoint. Which command used to close the found connection? This task is similar to the Russinovich TCPView program. private void...
4 Aug 2019 by Leonid Kazakov
First of all visit CurrPorts: Monitoring TCP/IP network connections on Windows and download programm CurrPorts. It seems that C # cannot solve the problem of closing the port. We will use the utility: private void ClearConnection() { string programma = Directory.GetCurrentDirectory() +...
20 Nov 2010 by compninja25
Hi Everyone,I'm working on a program that needs to transmit some information to a remote server for processing. I have packaged the two objects into a byte stream, but seem to be having trouble figuring out how to send both of them.There are a lot of great examples out there for sending...
20 Nov 2010 by jim lahey
Streaming with WCF might be for you:[http://msdn.microsoft.com/en-us/library/ms731913.aspx]
21 Nov 2010 by compninja25
Hi Jim,Thank you for helping me with this. After reading through that, It also makes more sense now to use buffering instead of streaming as I need all the information there before I can deserialize, and it also helped me stumble across another example article found here.
25 Oct 2011 by Jackie00100
hi im working on a simple IM chat messenger and every thing works fine as long as i sends a "controlled" amount of lines to the server but what i want is to let the user be able from the chat window to send multiple lines. at the moment im using readlines because i cant get .read or .write to...
25 Oct 2011 by BobJanova
NetworkStreams don't guarantee that one send = one receive. So you either need to add a delimiter which marks the end of a message, and buffer results until you reach it (ReadLine is doing this for you automatically), or you need to send a message header which includes the message length before...
28 Dec 2011 by Nirvana19933
hi every body,i need some help and i hope you can help me.because i started to programming a little tool in c# to send some telnet commends to my fritz.box 7141 to controll the led-lights. but in my programm in dosn´t works an i don´t know why. i wont to send the commend "echo 1,3 >...
28 Dec 2011 by Nirvana19933
i have no syntax errors in the program. but im not able to send the the comment "echo 1,3 > /dev/new_led" to the fritzbot, there is no reaction. and now i thing i send it wrong
30 Nov 2014 by Member 11273665
I made an application for remote control a pc specifically for control the strategy game Age of Empires 3 (so I can control two civs using one pc). The application uses UDP protocol to send the captured image (I inject a dll to the age3.exe proccess and I hook the DirectX EndScene function so...
30 Nov 2014 by Dave Kreskowiak
Can it cause your hardware to fail? Nope.This sounds like an ISP problem or at most bad hardware and it's just a coincidence that your app happens to be running.
18 Dec 2013 by Member 8028486
I have a C# application which listens for incoming TCP connections and receive data from previously accepted connections. Please help me whether i use Threadpool or Async methods to write the program?? Note that, once a connection is accepted, it doesn't close it and continuously receive data...
17 Mar 2016 by Member 10525430
Hello,i want to use my tcp server and client in same pc.does it possible?What I have tried:nothing specialcreating codetesting same pc
17 Mar 2016 by RickZeeland
Here is a good article about a Client / Server application in C#5:Creating a server/client application using native .NET TCP library[^]As the author says: Quote:Note that I would use loop back address (127.0.0.1) and a sample port number (1234) because I am going to use my own machine to...
8 May 2011 by canard29
HI all,How to develop in C# a program to communicate (send and receive) with this existing C++ library ??This library is already developed and I can't change it.I tried putty with this parameters with success :http://athiri.cimds.ri.cmu.edu/files/TcpBridge-putty.jpgThink you...
9 May 2011 by Kim Togo
Check out TcpListener[^], there is two good examples on how to use TcpListener and TcpClient.TcpListener server=null;// Setup listener, accept on any IP address on local computer on TCP port 13000.server = new TcpListener(IPAddress.Any, 13000);// Start to listen for...
8 Jul 2016 by Srinivas Reddy Tanubuddhi
I am pretty new to this Networking stuff in .net.I need to establish a TCP channel between 2 machines and their ports. Machine A is vncclient, Machine B acts as Routing Server, Machine C is vncserver.1.Machine A Sends the requests to MachineB 5900 port2.Need to establish a channel...
8 Jul 2016 by Member 4320844
Quote: Using VB6 or C# Language, I think you should try to Execute netsh Command Using Shell( ) to port forward, see the commands below:' -------------------------------------------------- NATIVE WINDOWS PORT FORWARD ( * MUST BE ADMIN)' To Port Forwar Use:netsh...
29 Nov 2014 by Member 11273665
What happens if I make a server application using tcp protocol and then establish connection with a client application but the server crash and then the client send data. Will the data be lost or the system will continue trying to send it?
29 Nov 2014 by Garth J Lancaster
'the system' ? no .. if the server crashes, the socket will (possibly after a timeout) be closed, at which stage the client should detect that the connection has been closed and take recovery action on its own. So, your client should, on recognising a disconnect, implement its own protocol for...
8 Apr 2013 by Craig Baird
A light weight easy to use .NET TCP server library
13 Dec 2016 by turcodel8
Hello @Devs, I'm trying to make a TCP communication with a GPS device that sends binary info through GPRS. I was working so far with several devices using UDP with ACK request to prevent loss of info.Well now I have to do a TCP comunication with gps, I probe multiple TCP listeners (thinking...
28 Jan 2014 by S Houghtelin
Sounds like you are having an issue with correct string encoding. You are receiving binary data which can be a problem.It looks as though you may be getting data but not being interpreted correctly. you may try using the following line of code using the iso-8859-1 Western European (ISO)...
18 Feb 2022 by payam purchi
can i get client is offline or online in new thread in server side ? it's mean when a client connected to my server i want check in new thread that The client is still online or not . What I have tried: NetworkStream client.getstram...
13 Jan 2012 by Emejulu JVT
Guys pls i need help figuring how to make this desktop application connect to the server located in another computer using wireless LAN. The applications( the client and the server) are TCP/IP network programs.this is an extract from the client and server codes:from client:using...
13 Jan 2012 by Richard MacCutchan
const string LocalHost = "localhost";... TcpClient myC = new TcpClient(LocalHost, port);Wouldn't it be better to try making a connection to the server?
13 Jan 2012 by Sergey Alexandrovich Kryukov
OK, you did not share with us what is your problem, but this code just don't look serious. You cannot seriously develop TCP communication without threading.You can get some idea from my past solution: Multple clients from same port Number[^].—SA
20 Mar 2021 by Member 14827175
deleted deleted deleted deleted deleted deleted deleted deleted deleted deleted deleted deleted What I have tried: unanswered unanswered unanswered unanswered unanswered unanswered unanswered unanswered
19 Feb 2021 by Richard MacCutchan
Yes, because you have declared the local variable handler, but you never initialised it to a valid reference. Look at you Send method, which takes a handler as its first input parameter. You need to get the same reference passed in to your...
23 Dec 2013 by Member 8028486
I have a c# Tcp listener program that listens for incoming connections and receive data from accepted connections during 15 second interval. But my application is not receiving any data after sometimes even the connection is not closed.Here is my codeclass Listener{ string...
5 Nov 2012 by m.bleimuth
Hi,i am trying to write some kind of a simple information System. My Server is written in c#, it sends every minutes udp heartbeats with Server Information (ip, port of the Server). Now i want to write a simple Website with html and JavaScript that connects to my Server and receives data...
5 Nov 2012 by CafedeJamaica
You can set up a TCPListener depending, if you google the class there is a very straght forwad example.http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx[^]make sure that you select the right version of .net for your client implmentation for the example.
16 Dec 2011 by dominikurban
I have some problems with TCP client on net Compact-Framework 3.5. My server application is written in C++ plus QT library and it's working on desktop computer. One of my clients applications is written in java on android platform and works fine. Also another desktop client written in C++ + QT...
16 Dec 2011 by Ganesan Senthilvel
you need to do a full IISRESET. I believe the "modern" recommended method when needing to have a web-hosted app fully restart is recycling the app pool as thus: iisapp /a /r (Windows 2003) or appcmd recycle apppool /apppool.name: (Windows 2008).
3 Feb 2011 by leemalin
Hey GuysI need some help with an app im writing. Its system tray app that monitors a service. when the user starts the service it should send a notification to all users who have the app opened, that person x is starting the service(a notification bubble should appear). All users on the same...
2 Feb 2011 by Steve Maier
You could look at using WCF to abstract some of the low level socket and TCP coding away. This way it is just in a configuration and you can forcus more on the app itself.Sasha did a good article on using WCF for a chat app. It might help you to see what WCF can do for you.WCF / WPF...
20 Jul 2010 by figassis
Hi, I'm trying to write a client application for a server which I have no documentation of. The Communication is done over TCP/IP.What I know of the server is:It's on another machine on a LANIt listens on port 4001It Receives messages on port 4001It sends messages to the client's TCP...
20 Jul 2010 by Richard MacCutchan
From your description it would appear that your client needs two parts.The sender portion should create an arbitrary socket which connects to the server port 4001 and communicates as necessary.The client also needs a listener socket bound to port 5001 which will accept connections from...
20 Jul 2010 by Aescleal
If you accept the general definition that a server is something that listens for a connection you haven't really got a straight client and server here... Both what you're calling your client and what you're calling the server are actually both clients and servers.So your "server": -...
21 Jul 2010 by figassis
Thank you all so much, and I actually got it working before coming back to check the answers and I am glad to see that I am indeed learning well. Had to get a piece of paper and make sense of it all with diagrams. You're all correct, I used wireshark again to see what was being exchanged between...
6 May 2013 by Member 10032335
Good Morning,After many years of not programming I need to dust off whatever rusty programming skills I might have had to try to build a couple of projects.We have some IP aware hardware interfaces and automation that I need to control and/or monitor, and I'm looking to use the Arduino...
6 May 2013 by Ron Beyer
If you don't think the Arduino is good, maybe try .NET Gadgeteer, that way you can develop both sides in C# which has a lot of code examples and code base to work from.Take a look at www.ghielectronics.com
8 Jan 2012 by amertarekt
Anyone know that we can call web service in C# using Add Web Reference in VS2008 and we can call it through c and c++ using SOAP library like gsoap librarythis library convert the xml string that is used to call the webservice and send it to it through a port is anyone know how can i do...
9 Jan 2012 by amertarekt
I solved it We can Call webservice using Tcp/Ip by sending the XML Code that is appearing under the page of function calling in the webservice page like thiehttp://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry[^]to port 80 and the server and wait for the HTTP responce