Click here to Skip to main content
15,885,278 members
Everything / Sockets

Sockets

sockets

Great Reads

by ObiWan_MCC
A C# SMTP server (receiver).
by Florian Rappl
Creating a highly extensible presentation app with multi-user and device integration for tablets.
by _m0n
Connect to PC with no public IP using Node.js app for reverse port forwarding / tunneling
by tonywilk
Example server and client using different protocols over a Websocket (php/js)

Latest Articles

by honey the codewitch
Explore adapting Socket's async model to a task based one and adding some awaitable socket operations to your projects
by Greg Utas
Replacing its erase() function
by Mircea Neacsu
C++ streams for socket communications in Windows
by pdoxtader
A multithreaded server class that accepts multiple connections from a provided client class. Each client can send and receive files and text (byte data) simultaneously along 250 available channels.

All Articles

Sort by Score

Sockets 

13 Aug 2013 by Florian Rappl
Creating a highly extensible presentation app with multi-user and device integration for tablets.
8 Jul 2017 by _m0n
Connect to PC with no public IP using Node.js app for reverse port forwarding / tunneling
10 Feb 2011 by Espen Harlinn
See the lines marked with "new" - You're pretty close to a working piece of code already.124. Send(handler, content); new. // All data received. Get next message. new. handler.BeginReceive(state.buffer,StateObject.BufferSize, new. ...
12 Sep 2011 by Kim Togo
If you want to use TCP connection, then there is NO broadcast. TCP[^] is a point to point protocol.Check out UDP[^].
1 Feb 2014 by tonywilk
Example server and client using different protocols over a Websocket (php/js)
15 Dec 2010 by EFEaglehouse
Windows CE/Mobile printing client for LPR, LPRng, and Socket API.
17 Jan 2011 by dasblinkenlight
In my experience, running your client in a virtual machine on the same computer as the server lets you simulate real-world client-server environments very realistically. Our company used VMWare's and Microsoft's virtualization products for debugging and in QA; both worked very well for our...
7 Feb 2012 by Sergey Alexandrovich Kryukov
We don't know what are your skills and habits. Easily? Hardly. If you wan to get anything good, anything at all — it's never easy. I would say easy is boring, how about you?Now, any language from your list would fit.(Of course assuming "VB" was just a bad joke.)—SA
26 Jun 2012 by OriginalGriff
This does more than you want (it retrieves the MAC address as well) but it does retrieve the IP addresses on the LAN - to convert them to the name is pretty simple: Retrieving IP and MAC addresses for a LAN[^] System.Net.IPHostEntry he =...
30 Jan 2013 by Sergey Alexandrovich Kryukov
First of all, when you talking about "server", it should be something which you develop yourself, because you will need to have some custom application-layer protocol:http://en.wikipedia.org/wiki/Application_layer[^].More exactly, a service. The term "server" is more often used in a narrow...
12 Apr 2013 by Manfred Rudolf Bihy
You're trying this the wrong way round. The server should have one socket (IP-adress and port) on which it accepts connections and then it will spawn a separate thread for each client that connects. If you were to do it your way you'd need either 40 IP adresses and listening on one designated...
26 May 2013 by Aravind.V.S
SocketIO - NodeJS desktop programming in C# using the SocketIO4Net library.
23 Nov 2010 by Rod Kemp
There is nothing you can do to your code to do this it is all about network routing.The server binds to the local IP address of the computer it is running on, you then need to put port forwarding rules into any modem/routers/firewalls between that computer and the internet (public IP or ISP...
16 Jan 2011 by Ashish Tyagi 40
First of all check whether your app is connected to internet using this link.. can you see me[^] put your listing port no and hit check button..If it failed probably you are listnig on 127.0.0.1(localhost) or your LAN address (like 192.168.0.10)so change your listing interface address to...
6 Feb 2011 by Espen Harlinn
You could do worse than starting out reading this book:http://www.cs.wustl.edu/~schmidt/POSA/POSA2/[^]It will not give you the answer, but it will enable you to understand how these things are usually done. Since you are writing a thesis, I would guess that you will have to understand the...
28 Oct 2011 by Sergey Alexandrovich Kryukov
Yes, I guess you have to search for a specific key word. The question is not quite clear, but I guess the key words should be "Push technology" and "Server push".You will find pretty good overview of the topic and available technologies here:...
29 Nov 2011 by Manoj K Bhoir
See this one :A light-weighted client/server socket class in C++
26 Jun 2012 by Tim Corey
Here is an article by Sacha Barber that has a working link:Retreiving a list of network computer names using C#[^]Basically, if you want to roll your own, I would recommend you first find your network IP address and Subnet. This will tell you what possible IP addresses other devices on...
29 Sep 2012 by pasztorpisti
As far as I know right we had full raw socket support in windows beginning with win2000 and ending with WinXP SP1. From WinXP SP2 only raw UDP sockets are available and even raw UDP sockets have some extra restrictions. More about these limitations here:...
25 Feb 2013 by Richard MacCutchan
You already posted this question at internet packet size help.....?[^]; if you have additional information to add then please edit the original.However, as I indicated in the previous question you can send a single byte via a socket. And if that byte only contains 1 significant bit of...
8 Jul 2013 by Reza Oruji
i have wtited a socket server application in java,it works good but after some connecting and disconnecting of client sockets ,the cpu usage of the application goes above the 65%are there any problem with my code ? this is my server application :import java.io.DataInputStream;import...
22 Jul 2014 by nitrous_007
Please help with this problem be patient and read through to the end. I will really appreciate it!!!I am creating 4 sockets on a computer with 4 network adapters and binding each socket to 1 network adapter. Network Adapter 1 is at 192.168.100.10. Socket 1 binds to Network Adapter...
8 Nov 2018 by Member 13737597
This article shows you how to implement trampolines on x64, introduces the idea of sync and async hooks, and dynamically added runtime filters and loggers.
23 Jul 2020 by honey the codewitch
Explore adapting Socket's async model to a task based one and adding some awaitable socket operations to your projects
2 Aug 2023 by Andre Oosthuizen
The problem you are facing is likely related to the way you are handling the data reception. Reading data from the stream using 'stream.Read' may not guarantee that you receive all the data at once, you should modify your code to read from the...
15 Apr 2010 by DaveAuld
Use the UDPClient class, here is the example straight from MSDN;// This constructor arbitrarily assigns the local port number.UdpClient udpClient = new UdpClient(11000); try{ udpClient.Connect("www.contoso.com", 11000); // Sends a message to the host to which you...
6 Jul 2010 by TickyTacky
Hi everybody,first of all I'm sorry about my poor english, as I am from Germany. I please you to excuse that.My Problem is, I'm trying to send a file via a Socket from one Computer to another. The Sockets aren't connected to each other, but to a Proxy, which handles the Communication....
4 Nov 2010 by OriginalGriff
This is very simplified - I ignore packet overhead, acks, response turnround, switch backplane capacity, and unicode.2KB = 2096 * 8 bits.100 messages per second = 100 * 2096 * 8.500 clients = 500 * 100 * 2096 * 8.= 838,400,000 bits per second.Are you using a gigabit network?...
9 Dec 2010 by Richard MacCutchan
As I said earlier, I think you still misunderstand the difference between a pointer and an array. In your reading code you have the following:for(v=0; v
18 Feb 2011 by Nish Nishant
Calling Socket.Disconnect(true) will internally result in Winsock's DisconnectEx function being called with the TF_REUSE_SOCKET parameter. From the docs:Prepares the socket handle to be reused. When the DisconnectEx request completes, the socket handle can be passed to the AcceptEx or...
8 Jun 2011 by Sergey Alexandrovich Kryukov
There are several levels you can use.Please see my past answer where I overview them:how i can send byte[] to other pc[^],Communication b/w two Windows applications on LAN.[^].What's the best for you really depends on your requirements.—SA
30 Jul 2011 by Shameel
There isn't a direct way to do it. However, you can use the HttpWebRequest/HttpWebResponse class to read the Html output from the webpage, parse the Html and rig the information you want.
28 Oct 2011 by RaisKazi
If I am not misunderstood your Question, You are looking for a something like called "Comet", In which their is a persistent connection maintained between Server and Client(Browser). Have a look at some Articles about "Comet" on CodeProject.Scalable COMET Combined with ASP.NETASP.NET...
6 Nov 2011 by RaisKazi
Try by calling one service at a time. Check are you able to connect to both your Web Services one at a time. From the Exception details it sounds to be your Service is unreachable from the Device.You may also post your Question on Android Developers...
14 Nov 2011 by Rajesh Anuhya
Here is the CP articleIntroduction to TCP client server in C#[^]
22 Dec 2011 by Chuck O'Toole
Ok, you have several errors in your logic. This biggest one is that you are passing the address of new_fd as the argument to the processing thread. The thread does *not* move that variable to a safer place but continues to use it through the pointer (i.e., *client_fd). That means you are...
26 Dec 2011 by CPallini
Well, what to say? Good luck with your homework.You know, this is 'Quick Answer' we don't provide complete code for homework. Please try hard yourself and if you're stuck then post here specific questions.
1 Jan 2012 by Sergey Alexandrovich Kryukov
nareshtest0101 wrote:I want to implement both, but I don't want to use RDP is there any other way?Of course you can create your own application-level protocol and implement it in your software. This is not very easy.First, the adequate form of the server side would be a Windows Service....
5 Jan 2012 by Sridhar Patnayak
Dear Abhishek ,Transmission Control Protocol is a connection-oriented protocol, which means that it requires handshaking to set up end-to-end communications. Once a connection is set up user data may be sent bi-directionally over the connection. So if the network is VPN,Lan or Intranet,...
15 Feb 2012 by Sergey Alexandrovich Kryukov
I'm not sure you can save too much of CPU time on custom marshaling compared to a binary serializer.However, you can potentially squeeze some extra performance, mostly by reducing redundancy. You can do it if you build you application-level protocol based on specialized and relatively rigid...
3 Aug 2012 by Philip Stuyck
Use an FTP library instead of coding this yourself.Suppose you really want to do this yourself, then you need to start with the server. Run the server which will listen on a specific udp or tcp port.Then you can create a client. In case of TCP it will first have to do a connect and then send...
3 Aug 2012 by Christian Graus
You just accept keyboard input but don't display it. You would use getch for this, which is in conio.h.
20 Aug 2012 by Sergey Alexandrovich Kryukov
The problem, if any, is somewhere else. Yes, I'm 100% sure.I little clarification: Thread.Sleep(0) is not equivalent to "no operation" or the code where this line is missing. To best of my knowledge, it takes some time for the method call, it cause switching the calling thread off and...
29 Aug 2012 by fjdiewornncalwe
Either launch 2 instances of Studio and debug them both at the same time, or bring both the client and server projects into one solution in which case you can run them both at the same time in 1 debug session there.
11 Sep 2012 by pasztorpisti
The solution is switching the socket to non-blocking mode and then waiting for the socket with select() until the socket becomes readable. With select() you can setup a timeout and when select() returns you can check whether the reason was a timeout or success/failure. If it was success then...
3 Jan 2013 by CPallini
The documentation [^] says it all: "Creates a WORD value by concatenating the specified (byte) values".It is just an auxiliary macro, useful if you have two bytes and need to 'glue' them in a word. A similar macro (whose usefulness is apparent) is RGB[^].
4 Jan 2013 by H.Brydon
A BYTE contains 8 (usable) bits. In this context, a WORD contains 16 bits or 2 BYTEs. These can be represented as +--------+--------+2 BYTEs |bbbbbbbb|bbbbbbbb| +--------+--------+1 WORD +wwwwwwww wwwwwwww| +--------+--------+You can build a...
25 Feb 2013 by Sergey Alexandrovich Kryukov
There is no such think as 1-bit package, quite apparently. The trick is: no matter what you do, you always create some application-layer protocol (http://msdn.microsoft.com/en-us/library/system.speech.recognition.dictationgrammar.aspx[^]) to conduct your application semantic in your network...
11 Mar 2013 by Richard MacCutchan
The client IP address is obtained from the socket returned by the accept() function[^]. Your code is trying to get it from the listening socket.
10 May 2013 by Sicppy
A DLL resource to help beginner to intermediate developers open and use sockets in a P2P application.
17 Apr 2013 by CPallini
(1) Both CreateProcess and fork creates a new process. However fork duplicates the calling process, while CreateProcess starts an executable. Both function allows the implementation of a multiprocess server.(2) Usually such servers are multithreaded, however nothing prevents you to make it...
12 May 2013 by Sergey Alexandrovich Kryukov
I think that using threads with blocking sockets instead of asynchronous API is much better. In most cases, communication is sequential in its nature and the flow of operations is logically independent from other threads. Therefore, using a separate thread for each communication channel (in case...
7 Jul 2013 by Sergey Alexandrovich Kryukov
Be logical: if you don't have any software on client which can handle a network message, its useless to send anything to it. From the standpoint of your network, such "client" does not even exist.—SA
4 Dec 2013 by Sergey Alexandrovich Kryukov
For this purpose, not only sleeping is not a "better way"; it is totally unacceptable because it causes race condition: http://en.wikipedia.org/wiki/Race_condition[^].Event if it works for you, it's just a matter of chance. It is not a legitimate way of thread synchronization. Sleeping has...
21 Dec 2013 by idle63
About 3'450'000 hints. I hope google sorted it acording to your requirements. http://stackoverflow.com/questions/12931528/c-socket-programming-max-size-of-tcp-ip-socket-buffer[^]
5 Feb 2014 by Sergey Alexandrovich Kryukov
The discussion in comments looks going well beyond the format of Quick Questions & Answers. You really need to design the server and client parts thoughtfully from the very beginning; so focusing on just your questions may not be so helpful. For some very relevant ideas, please see my past...
13 Aug 2014 by Rob Philpott
I have a simple thing which listens on a socket for incoming connections. It binds to the 'listen' socket, BeginAcccepts the socket, calls EndAccept in the handler then immediately re-issues the BeginAccept.This all works well here in London, and it's happily accepting 20+ short lived...
30 Sep 2014 by Wendelius
In my opinion a VPN connection isn't comparable to a socket conversation. VPN is about creating a private network 'extension' in a public network. In most cases it's used for security but also offers other benefits. You can still communicate via socket within a VPN. For more information see...
13 May 2015 by Jalal Ali
A guide on sockets, and how to send objects across them
17 Nov 2015 by CPallini
This is your own homework and you have to do it yourself (ask here just specific questions when you're stuck). As a side note, there are many, many (did I say 'many'?) tutorials available on C/C++ socket programming on Linux (an I bet you could easily find a ping implementation example).
13 Feb 2016 by CPallini
As Richard pointed out, if you want to do socket programming then you have to use IP addresses (or hostnames, and anyway, you haven't to worry about the IP address assigned to your own ethernet card). In order to start with socket programming you have to read the f#*?+° (fantastic)...
22 Aug 2016 by Jochen Arndt
You are using blocking sockets. When receiving and there are no more data, the recv function will block (not return) until new data are received or the connection is closed (as triggered with your third try).The simplest method to avoid this is using some kind of indication that all current...
4 Jul 2017 by Jochen Arndt
So the code works and the connection is there but you just don't get what you want. That is because you are communicating with the server on the raw HTTP level. The received data will begin with an HTTP response that you have to analyse. If you don't want to do that yourself you have to use a...
25 Jan 2018 by Nazar.Bukhari
An article on how to implement Observer Design pattern in Mutithreaded Java application when Function pointer is needed
30 Jan 2019 by Stefan_Lang
There are several problem I see with your code. 1. Your variable, command_header, is not initialized completely: only the command is assigned, but you never fill its DataBuffer. Did you mean to read the data from SourceFile into that buffer? If so, you need to copy it from buffer, and make sure...
11 May 2010 by «_Superman_»
You cannot bind a socket to an ip address and port more than once.Check if your bind call is doing this.I'm guessing you're calling bind inside a loop.If so, try moving it out of the loop.I would also recommend you use I/O Completion ports.
15 Jul 2010 by Simon Dufour
There's an example on this site.C# Sockets and Serialization[^]You might want to take a look at this library.Lidgren networking library[^]The problem with a multiplayer racing game is that things go fast. You might get desync issue or cars that warp everywhere. Multiplayer...
25 Aug 2010 by _rubinho_
I'm writing some code in C# for the first time which requires talking to a network attached device using HTTP. Unfortunately the device is broken and so I cannot use the HttpWebRequest/HttpWebResponse classes, so I'm having to do it myself with TcpClient and NetworkStream. I've got the...
2 Oct 2010 by linayang
thank you Ash and CPallini.I put the code here which occurs the error,int WinSock2Server::STEP5_ReceiveAndSendData(SOCKET ClientSocket){char recvbuf[DEFAULT_BUFLEN];int recvbuflen = DEFAULT_BUFLEN;char sendbuf[DEFAULT_BUFLEN];int sendbuflen = DEFAULT_BUFLEN;int iResult,...
3 Oct 2010 by Richard MacCutchan
Just for the record, the following shortened form of your code compiles successfully:using namespace std;template struct Router{ T rval;};// Ended//YLN added 2010-09-25template void testList(Router &listObject, const string &typeName){...
16 Oct 2010 by DasKaiserJohan
Hello,I have written a char server and a chat client application. I have a little problem though;I store the names of all connected chat clients in a list. When a new client connects, he will receive the list through a socket. The method that iterates and sends it over the socket looks...
4 Nov 2010 by Anthony Mushrow
I believe that even if you have enough bandwidth to cope with the amount of data you want to send, there's too much overhead and latency with sending that many packets. When sending over TCP you need to send the packet which will have a small delay as it gets sent onto the actual network...
20 Nov 2010 by jim lahey
Streaming with WCF might be for you:[http://msdn.microsoft.com/en-us/library/ms731913.aspx]
29 Nov 2010 by Indivara
There's a sample on MSDN. Seek and ye shall find.
3 Dec 2010 by Vishal Kumar Soni
Hi,I am bit confused about following lines from MSDN to related connect API:"With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR"I have following doubt1) If connect is not able to make connection than it...
7 Dec 2010 by Richard MacCutchan
n = write(newsockfd,&handFace[y],sizeof(handFace[y]));You are sending the pointer to the string and length of a pointer rather than the string itself and its length. Your code should be: n = write(newsockfd, handFace[y], strlen(handFace[y]));Same thing with the suit. You could...
20 Dec 2010 by nortee
Hello,I've found that using the Indy components that come with Delphi work quite nicely for anything to do with socket programming. There are a few demos that come with it as well including emailing, FTP, TCP/IP and more. If your version of Delphi does not have these demos you should be able...
16 Jan 2011 by Seyed Hamed Khatami
Hi!I made a program using the socket class in C# which is a chat program. In LAN network I can work with it, but over the internet I can't.Can you guide me?Thanks in advance!
17 Jan 2011 by ad_robot
Hi Everyone, I'm implementing asynchonous socket programming in (C++, winsock, TCP/IP, based on this example Chat Client Server[^]) at the moment (for data streaming) and am running into problems with missing data when I run the code over a network rather than locally (I only seem to recieve...
6 Feb 2011 by #realJSOP
You picked a programming project for your thesis, and you don't even LIKE programming? Beyond that, writing a thesis involves YOUR OWN research, not ours. research it, LEARN how to do it, and then write your thesis.
18 Feb 2011 by #realJSOP
Really? Evaluate the requirements, decide on your supported platform, and choose the appropriate language/framework. Analisys part of learning how to be a programmer.
25 May 2011 by Dave Kreskowiak
Your kind of looking to write your own web client, but there's no need to. The existing web client classes can be used in a multithreaded environment.You cannot use the WebBrowser control (in the ToolBox) in anything other than the UI thread.
4 Jun 2011 by Manfred Rudolf Bihy
Synchronize your computers via NTP (> Windows 2000) or SNTP (
4 Jun 2011 by Manfred Rudolf Bihy
I've added this as a separate solution since the requirements where not known from the start.I presume the machines are dedicated to this task only and don't have any other purpose than to play one video spread over several screensHave the application run when the machines are...
8 Jun 2011 by Kim Togo
I think the most versatile solution is Windows Communication Foundation[^].But it depends on how complex the solution is. More simple solutions is just to exchange a XML document.
14 Jun 2011 by Ciumac Sergiu
Hi,you cannot bind your socket to a foreign IP address. If 164.11.116.39 is not the ip from a network interface of a computer on which your program is running, you won't be able to bind a socket to it. Regards
3 Aug 2011 by VicAngeline
How to program a chat tool by C# language?I want to learn network programming,and I hope to write a Winform Application which can be used to chatting.But I don't know how to do it,do I need to learn socket or other knowlege?
3 Aug 2011 by Shameel
Here is an excellent WCF Chat Application[^] written by Sacha Barber. There are other examples in Code Project that uses socket programming instead of WCF. You can try searching for terms like "C# chat", etc.
27 Aug 2011 by Simon Bang Terkildsen
the string you pass to atoi is not null terminatedyou have less than 3 arguments. You haven't ensured that you have 3 arguments thus result = atoi(argv[2]); might fail.Stepping through your code line by line, with the debugger, will allow you to find the line that fails and it should be...
11 Sep 2011 by Sergey Alexandrovich Kryukov
Yes, you need to listen to a port all the time. The "trick" is: you need to listen the way spending zero CPU time. The thread should call a blocking method which puts the thread in a special wait state; it is switched off by the OS and never scheduled back to execution until a connection comes...
16 Oct 2011 by Pranit Kothari
Hello,I wanted to create simple client server application using WinSock2 APIs. I wanted to use Asynchronous socket programming for that. Can someone give me sample code for that. Also, as a programmer, I do not want to go in deep concepts of Networking but wanted some understanding of it. Can...
26 Oct 2011 by Jimmanuel
>> I have to receive and storage this data somewhere continuosly in order to process it, in the meantime I need to keep receiving the server data because I cannot lose any part of the server messages.The socket will buffer data for you until you read it, but if the buffer becomes full it'll...
28 Oct 2011 by renasis_
Hello,Does anyone of a project where a socket was used to pass the communication between a server and a browser? Yes, like a websocket, but w/o. Basically, you would have a program that would create two socket connections. One with the browser and another with the server, pass the...
3 Nov 2011 by Mehdi Gholam
Read these : http://www.giantflyingsaucer.com/blog/?p=15[^]http://forums.adobe.com/thread/97721[^]
13 Dec 2011 by Richard MacCutchan
Use Google to find source code for sockets in Java. Once you have created the socket the language has nothing to do with it. The only issue is that the data you transfer between client and server must be in a form that both ends agree and understand. Simple ASCII bytes is probably the best form,...
14 Dec 2011 by Nagy Vilmos
Further to Richard's excellent answer, look here[^] for some easy examples of writing a Java TCP/IP client.
15 Dec 2011 by Richard MacCutchan
The server listens on the fixed port, and when a client connects it will redirect that connection to a dynamically created port. The client and server will now communicate through the sockets on the dynamic port, while the server continues to listen on the fixed port for other connection requests.