This is the simplest way I could do it. Find the code here (it's a bit more organized): github.com/Abl... BTW: Use Buffer.BlockCopy() same syntax but faster
Your source helped me a lot with my uni project, made me kinda understand how to use C# implementation of sockets and how to serialize data for that. Not all heroes wear capes, thank you.
Thanks for the awesome tutorial. I'm currently designing a multiplayer hacking simulator which I will now be able to program thanks to this tutorial :) It's basically just going to be command based where the client types in commands and the commands, clients and other data is dealt with in the server. Thanks a heap :D
i was trying to learn about socket programming and this video is awesome, just watched once then i wrote my own server and client. thanks for sharing....
Excellent job teaching Sockets. Though, I would have preferred if you took time to comment your code. Not because it necessarily needs comments (though they might help explain things a bit better) but more because otherwise you go very fast! I had to pause and go back several times. Still, learned more about working with sockets tonight than I ever did trying to read the docs.
4:30am testing, ah the exciting life of a programmer. few minutes off from when I'm watching to attempt a similar objective. Nice tutorial. Verbalizing as you worked away was very helpful in understanding the reasoning for your choices.
Oh thank god. This is so much nicer than the TcpListener/TcpClient api, which is all I've seen in google results. I've been using sockets directly like this for Udp traffic but wasn't sure that I could do the same for Tcp.
Hey man, your tutorial is awesome and I did understand it. I have one problem though, if I try to send data from another computer in the network it doesn't work. I try to change the listening IP to a specific IP and it only accepts connections that come from my computer's IP. If I try to send anything through the network, i.e. from another computer either A) it does't see the data coming (when socket is bound to "IPAddress.Any") B) it crashes at server setup (when socket is bound to an external (LAN address)) Do you have any idea on what is wrong?
Great Video.. you are a great programmer .I am big FAN of yours. Thanks for this video...it helped me to understand our company project which is also using socket programming.
If you want to fix the error when the client disconnects, replace the code in the ReceiveCallback function with this: Socket socket = (Socket)ar.AsyncState; try { int received = socket.EndReceive(AR); byte[] dataBuf = new byte[received]; Array.Copy(_buffer, dataBuf, received); string text = Encoding.ASCII.GetString(dataBuf); Console.WriteLine("Text received: " + text); if (text.ToLower() == "get time") { SendData(DateTime.Now.ToString(), socket); } else { SendData("invalid request", socket); } } catch { Console.WriteLine("client disconnected"); socket.Close(); socket.Dispose(); }
If a client disconnect, should I remove him from _clientSockets list? also, if I'm creating a game (just for example) with a login screen and etc, I'd have to call the "loopconnect" at the login button? Also, how can I force a client to disconnect (and make him know that he has been disconnected)? I'm thinking about just calling something like _clientSockets[0].Close(), _clientSockets[0].Dispose(), _clientSockets.remove(0); but I don't know what would happen with the client at this point. Also, thanks for your fix!!
Nice video, now the following question occurs to me; if i want to send a message from one client to the other(s) via server (client1 -> server -> client2), do i just use a loop and count through all the connected client sockets like "clientSockets[i].Send(data); i++;"
if the ports specified in code don't work, then set the port's number higher than 1024, I forget if port 100 is used by the system or not, but there are a LOT of open ports available, excellent tutorial tho!
Ya, if your clients disconnect ungracefully, you can get exception in various points of the server. You need to handle these errors and remove the client form your client list when they occur for a specific client.
Great Tut. I Learned something. But sir, why my client side only can request one time only? an also I tried with my two laptops connected to one router but the client cannot connect to server? Please response as soon as you got time. Thanks
Hello, when the client socket is disconnected, the socket server is also closed, is the process normal? I needed the server to stay alive. Can you help?
i get this error for int received = socket.EndReceive(AR); unhandled exception: system.nullreferenceexception:object reference not set to an instance of an object.
Well the Speech namespace does not provide freeform dictation, but you can try to load an entire English dictionary as grammar. You would then perform tests on the results like anything else. This is a long shot though
Hi, Nice tutorial. Learned a lot from the video. However I have a doubt as to how can we handle the request based on timer...means I want to disconnect the socket connection if i don't get response from any client. May be 5 seconds for instance and the time for each client starts from the moment they are connected and whenever they send response, the particular timer for the client resets to 5 secs. Thanks.
The idea is that the boards read some sensors, after that the data is processed by the firmware within the micro-controller and than is sent using Ethernet protocol to the server. Another situation is when I send from the server a command and the firmware within the micro-controller will process it and do a different task. So my question is whether the video that you presented can be adapted to do this, because I think that I must to use the same Socket class.
How would you go about checking everyone who's connected to the server and sending messages from the server to any client at any given time, not just as a response to a request from a client. Sort of a push notification.
Hello Brian. I'm interested in executing OS commands on multiple servers in parallel ..ie to stop and start applications on all servers at once. I'm using VS Studio WPF C#...also considering integrating python or windows powershell, but hope to use C# only...do you have any tips? Will the method of programming sockets in your video work? I'm new...please share tips?
I dont know what I have done wrong but the server is just saying the exact same thing I say so if I say get time it says received get time but on the server console it shows i am connected and shows what I said its as if the client is just printing what I am typing instead of the server response or its as if the server is just sending the same data back I have watched this video more than 10 times and our code matches is this a problem with visual studio 2017
hey .. great video . concepts still a bit unclear . can u tell where exactly a new thread is spawn and when socket.close is called whether in client or server code then what exactly should happen in terms of where the program control get transfered. thanks
How come mine stops receiving from a client when the receive callback is called? I mean to say it only works if I put the beginreceive command at the end of the receive callback, is this normal?
I am as I'm working in a group on a chat program with a GUI built using WPF in Visual Studio. I take no part in creating the GUI, but only the server. I have worked with very simple servers before, but I am seeking advice on how to go about this. The most important thing is to be able to receive and store information, I would imagine writing to a text file, but I am hesitant.
Everyone who wants to send the time to all clients at once you would need to loop through the socket list sending it to all at once for instance List socketList = new List();//Will be full of connected clients foreach(Socket s in socketList) { byte[] data = sendString("time string here"); s.Send(data); } public byte[] sendString(string msg)//method for converting bytes into strings { byte[] data = Encoding.ASCII.GetBytes(msg); return data; }
Its in my best interest to disregard byte accumulation for this video. And I dont know what you mean with the callbacks. And by the way, I will have another vid on receive past buffer size which will be much more robust than the other one.
This works fine when I run the client and server on the same computer. But when I run them on two different computers they never connect. These are computers that are connected via WiFi in my home and can share files. So why isn't this working? Do I need to specify IP addresses?
Greetings @LeftTechticle , I liked your video and I liked your example even more. I hope you don't mind me asking you this.. I'm working on a multiplayer card game (just to learn, no specific reasons) and I stumbled upon your video trying to find a solution to server/client connections. In your example, the client is just as is on the server, in other words, server doesn't care who the client is.. but is there a way to differentiate separate clients? or send sort of an object containing information about the specific client to the server?
Thanks for tutorial, it's awsome. But i am trying to figure out how can i make multiple connections for the basicasyncserver and basicasyncclient? how can i turn them into accpet multiple connections?
i have done the same code and it worked fine. i made some changes like from server side i changed responce on switch(text) and it worked well but when i tried to read() some responce from serverside, on run time it throws exception of socket , at int rec = _clientSocket.Receive(recievedBuf); if someone can help ???
Did anybody get a NullReferenceException for "int received = socket.EndReceive(AR);" when putting in a request? It gave an error and shut down the server.
I tried this code, and it works... but somehow. the server stops listening and i got this. "The thread '' (0x1768) has exited with code 0 (0x0)." Any helps?
Its probably not a good idea to try to predict where threads are spawned in Async methods. Just know whether you on a UI thread or not (print out your current thread IDs or something to see). BTW this vid is not meant to explain the behavior of anything, it was just to present a simple design pattern for multiple clients.
I need to construct a server which can receive/store the information in a "friends list" from a client for a chat program. Do you have any suggestions?
Nice tutorial. How can I safely close a socket from client side? Cause' when a client exit the server crash and if not crash (the server not crash every time) and I restart the client server not answer the requests.
all you have to do is use a try { Put the procedure of code that errors it will fix when the client disconnects } catch(SocketException) { Console.WriteLine("Client Disconnected") }
Does anybody know how to use this to connect two computers that aren't connected to the same router? (IE, in the same house.) I've never done any network programming or socket programming before.
hey if the client sends a msg end then the server closes that particular socket. but if i close my client console window then my server crashes. can u suggest how to resolve if the client closes the console window or stops running its program then the server must still remain on . thanks :)
Hi sir, I have two stepper motors connected to my PC using Ethernet cable, is your code able to realize the communication between PC and stepper motor? for example I could send command from clientSide and get response from server side? thank you
I have no way of determining this. Assuming you are connecting to a microboard with compact .net framwork, and all of the references can be resolved, then the code will run fine. Other than that, you should check the CLS compliance of code before installing it on a microboard.
How to detect now if a client disconnects properly?! I could send a 'left' message but if i kill the process of the client for example in task manager... how to let the server detect the disconnect of the client
You mean the first letter? Because if I did that it would be akward considering all methods in the framework use PascalCase, plus 97% of 3rd party C# methods.
I have a problem, i open 1 port at My Router, I sent to my friend IP Router and this Port. My friend can chat with me by using Socket Chat Application, I also chat with myselft by using this. But 1 program like as Skype or web as facebook not only don't need open a port, but also message is sent. I don't know how I do it? Hope you give me more inforamation usefully, thanks
Everything you need to know is on this SO post or linked in this SO post regarding Skype's methodologies: stackoverflow.com/questions/1539339/how-does-skype-work-without-port-forwarding You can also create dedicated servers and relay everything through them (clients don't need to port forward, only the servers).
Nice video. I want to create a server that send commands to 50 electronics boards, and receive information from that boards. All boards have a micro-controller with Ethernet integrated. Could you show me how I can communicate with this boards?
as I can make one client message is sent to the server and the server will send that message to the client 2 ? thanks , PS: I've been with your video from multiple clients, but I need him as a server that can transmit the message from the client 1 to client 2
I think using the Socket class would be the best. Theres abstractions like TcpClient and TcpListener that don't seem to make anything easier. I cant tell you if it would be appropriate to adapt the sample. The sample wont be able to retrieve large amounts of data. As well its better just to put all of this stuff in a class library if it were any more complex than this.
if the client lose the connection with the server how can I reconnect to there. Because I tried to turn back the to the loopback(); but it is not connecting back.
There's an access violation exception when the server sends the time to the second (or third or fourth etc.) clients. The first client that connects works perfectly fine though. Also I did not modify any of the downloaded files.
hi I got this exception The IAsyncResult object was not returned from the corresponding asynchronous method on this class. and it is under the private static void AcceptCallback(IAsyncResult result) on the line Socket socket = ServerSocket.EndAccept(aresult); please take look at this link stackoverflow.com/questions/31139784/the-iasyncresult-object-was-not-returned-from-the-corresponding-asynchronous-met I could find the problem. thanks
to make this work through an external ip. The external ip needs to be static and the port you used needs to be port forwarded. if the ip is not static then whenever your network changes you will need to change the client ip to your new ip
ScriptSpyOfficial Hmm, this doesn't seem to work. Do you mean to use an ip address from www.whatsmyip.org/ ? In order to have a static IP, I am pretty sure you need to own that IP (through a website). I may be wrong about that however.
Your source helped me a lot with my uni project, made me kinda understand how to use C# implementation of sockets and how to serialize data for that. Not all heroes wear capes, thank you.
Thanks for the awesome tutorial. I'm currently designing a multiplayer hacking simulator which I will now be able to program thanks to this tutorial :) It's basically just going to be command based where the client types in commands and the commands, clients and other data is dealt with in the server. Thanks a heap :D
That was awesome! Not only did you help me get a better understanding but you also made me go further, so thank you very much!
You are one of those guys people stand behind and watch code, great tutorial.
i was trying to learn about socket programming and this video is awesome, just watched once then i wrote my own server and client.
thanks for sharing....
Excellent job teaching Sockets. Though, I would have preferred if you took time to comment your code. Not because it necessarily needs comments (though they might help explain things a bit better) but more because otherwise you go very fast! I had to pause and go back several times.
Still, learned more about working with sockets tonight than I ever did trying to read the docs.
Indeed, I am going to get around to the source and apply comments to it at least. I've been refactoring everything.
4:30am testing, ah the exciting life of a programmer. few minutes off from when I'm watching to attempt a similar objective.
Nice tutorial. Verbalizing as you worked away was very helpful in understanding the reasoning for your choices.
Great job. You just saved my life and teaches me something fantastic.
Oh thank god. This is so much nicer than the TcpListener/TcpClient api, which is all I've seen in google results. I've been using sockets directly like this for Udp traffic but wasn't sure that I could do the same for Tcp.
How did you add a second Client at 26:30?
Thank you for this Tutorial! Very usefull to understand how sockets work in C# :)
Thanks a lot dude! Very easy to follow along, you spoke clearly, and explained what each method did.
A++ would recommend.
Would be bad if you gave him C++. HAHAHA dem programmer jokes....
Vukasin Vucenovic lol
THAT was AWESOME (Y) really thank you man, you are very pro brother, thank you , that was what I was searching for it for about 2 weeks (Y) THANK YOU
Hey man, your tutorial is awesome and I did understand it.
I have one problem though, if I try to send data from another computer in the network it doesn't work. I try to change the listening IP to a specific IP and it only accepts connections that come from my computer's IP. If I try to send anything through the network, i.e. from another computer either
A) it does't see the data coming (when socket is bound to "IPAddress.Any")
B) it crashes at server setup (when socket is bound to an external (LAN address))
Do you have any idea on what is wrong?
Great Video.. you are a great programmer .I am big FAN of yours. Thanks for this video...it helped me to understand our company project which is also using socket programming.
If you want to fix the error when the client disconnects, replace the code in the ReceiveCallback function with this:
Socket socket = (Socket)ar.AsyncState;
try
{
int received = socket.EndReceive(AR);
byte[] dataBuf = new byte[received];
Array.Copy(_buffer, dataBuf, received);
string text = Encoding.ASCII.GetString(dataBuf);
Console.WriteLine("Text received: " + text);
if (text.ToLower() == "get time")
{
SendData(DateTime.Now.ToString(), socket);
}
else
{
SendData("invalid request", socket);
}
}
catch
{
Console.WriteLine("client disconnected");
socket.Close();
socket.Dispose();
}
thanks for this!!!
What's the SendData function?
Where the f**k did that SendData function come from?
tank you ^^
If a client disconnect, should I remove him from _clientSockets list?
also, if I'm creating a game (just for example) with a login screen and etc, I'd have to call the "loopconnect" at the login button?
Also, how can I force a client to disconnect (and make him know that he has been disconnected)? I'm thinking about just calling something like _clientSockets[0].Close(), _clientSockets[0].Dispose(), _clientSockets.remove(0); but I don't know what would happen with the client at this point.
Also, thanks for your fix!!
ah , no need to convert port's byte ordering like in c++ ...you know why I don't neeed glasses? because I can C # .. lol
i have no idea what you said about c++, im no c++ literate but i like your joke :)
Wait, does that mean I can't C# because I do need glasses?... but I can C#. It's a paradox!
Lmao
Nice! Can you connect this short client/server app with a database ??
Nice tutorial! But why make the buffer static? All recevied data from clients will then be put in the same buffer.
Nice video, now the following question occurs to me; if i want to send a message from one client to the other(s) via server (client1 -> server -> client2), do i just use a loop and count through all the connected client sockets like "clientSockets[i].Send(data); i++;"
if the ports specified in code don't work, then set the port's number higher than 1024, I forget if port 100 is used by the system or not, but there are a LOT of open ports available, excellent tutorial tho!
It works great but if I exit out of my client it causes errors in my server and shuts it down.
superb tutorial;used to be scared abt socket programming
My visual studio says that Socket does not contain definition for BeginAccept help please. Tried in windows forms and actually works
I don't know if you don't pay attention but is there something for when a socket is disconnected?
Because when I close a client the server crashes
what resources could I use to learn about programming stuff like this?
Ya, if your clients disconnect ungracefully, you can get exception in various points of the server. You need to handle these errors and remove the client form your client list when they occur for a specific client.
Great Tut. I Learned something. But sir, why my client side only can request one time only? an also I tried with my two laptops connected to one router but the client cannot connect to server? Please response as soon as you got time. Thanks
Hello, when the client socket is disconnected, the socket server is also closed, is the process normal?
I needed the server to stay alive.
Can you help?
i get this error for int received = socket.EndReceive(AR);
unhandled exception: system.nullreferenceexception:object reference not set to an instance of an object.
can we make send data from server to client ? even before server receive data from client?
Well the Speech namespace does not provide freeform dictation, but you can try to load an entire English dictionary as grammar. You would then perform tests on the results like anything else. This is a long shot though
Hi,
Nice tutorial. Learned a lot from the video.
However I have a doubt as to how can we handle the request based on timer...means I want to disconnect the socket connection if i don't get response from any client. May be 5 seconds for instance and the time for each client starts from the moment they are connected and whenever they send response, the particular timer for the client resets to 5 secs.
Thanks.
The idea is that the boards read some sensors, after that the data is processed by the firmware within the micro-controller and than is sent using Ethernet protocol to the server. Another situation is when I send from the server a command and the firmware within the micro-controller will process it and do a different task. So my question is whether the video that you presented can be adapted to do this, because I think that I must to use the same Socket class.
How would you go about checking everyone who's connected to the server and sending messages from the server to any client at any given time, not just as a response to a request from a client. Sort of a push notification.
Hello Brian. I'm interested in executing OS commands on multiple servers in parallel ..ie to stop and start applications on all servers at once. I'm using VS Studio WPF C#...also considering integrating python or windows powershell, but hope to use C# only...do you have any tips? Will the method of programming sockets in your video work? I'm new...please share tips?
Hi Brian. Congratulations.Good tutorial !! Do you have some example from this point to implement WebSocket Server in C# using Socket ?
I dont know what I have done wrong but the server is just saying the exact same thing I say so if I say get time it says received get time but on the server console it shows i am connected and shows what I said its as if the client is just printing what I am typing instead of the server response or its as if the server is just sending the same data back I have watched this video more than 10 times and our code matches is this a problem with visual studio 2017
In order to stop it closing you have to add Console.Readline(); in the Main. Make sure it is your last code in the Main.
Hey thanks for the video, I've just decided to get into network programming and this is a great introduction.
hey .. great video .
concepts still a bit unclear .
can u tell where exactly a new thread is spawn and when socket.close is called whether in client or server code then what exactly should happen in terms of where the program control get transfered.
thanks
Are you looking for suggestions on creating a chat program?
Hey im unsure if you still do tutorials but can you please make another video just like this but goign mroe in depth
How come mine stops receiving from a client when the receive callback is called? I mean to say it only works if I put the beginreceive command at the end of the receive callback, is this normal?
I am as I'm working in a group on a chat program with a GUI built using WPF in Visual Studio. I take no part in creating the GUI, but only the server. I have worked with very simple servers before, but I am seeking advice on how to go about this. The most important thing is to be able to receive and store information, I would imagine writing to a text file, but I am hesitant.
How about out of loopback IP usage of your project? Because I did a project but it can only run as loopback IP(127.0.0.1)
Excellent! Do you know if it is possible to do a raw socket in win7?
For socket which the best C or C#? Or any language
Everyone who wants to send the time to all clients at once you would need to loop through the socket list sending it to all at once for instance
List socketList = new List();//Will be full of connected clients
foreach(Socket s in socketList)
{
byte[] data = sendString("time string here");
s.Send(data);
}
public byte[] sendString(string msg)//method for converting bytes into strings
{
byte[] data = Encoding.ASCII.GetBytes(msg);
return data;
}
Its in my best interest to disregard byte accumulation for this video. And I dont know what you mean with the callbacks. And by the way, I will have another vid on receive past buffer size which will be much more robust than the other one.
Thanks for this amazing tutorial! Is this applicable on Unity? I set client code on unity, But when I ran server on pc it didn't work
This works fine when I run the client and server on the same computer. But when I run them on two different computers they never connect. These are computers that are connected via WiFi in my home and can share files. So why isn't this working? Do I need to specify IP addresses?
Greetings @LeftTechticle , I liked your video and I liked your example even more. I hope you don't mind me asking you this.. I'm working on a multiplayer card game (just to learn, no specific reasons) and I stumbled upon your video trying to find a solution to server/client connections. In your example, the client is just as is on the server, in other words, server doesn't care who the client is.. but is there a way to differentiate separate clients? or send sort of an object containing information about the specific client to the server?
why didn't you make a separate class for the client? just wondering
Can make the code for your Socket programming example available on your link you provided...I was not able to find it. Great job on the example.
Hello! How can I allow connections from clients outside of my local network?
Thanks for tutorial, it's awsome. But i am trying to figure out how can i make multiple connections for the basicasyncserver and basicasyncclient? how can i turn them into accpet multiple connections?
Take a look at threading
i have done the same code and it worked fine. i made some changes like from server side i changed responce on switch(text) and it worked well
but when i tried to read() some responce from serverside, on run time it throws exception of socket ,
at int rec = _clientSocket.Receive(recievedBuf);
if someone can help ???
Thanks a lot dude, it was something new from my experiance.
Would this stuff be used to make server FPS stuff or is this more for things that doesn't require fast updates?
Error 1 The type or namespace name 'IPEndPoint' could not be found (are you missing a using directive or an assembly reference?)
using System.Net;
using System.Net.Sockets;
+Madarász Bence Add using System.Net; and using System.Net.Sockets; to the top of the file at the namespaces
What does the buffer do? What happens if you dont use a buffer?
can it work like a public server I meant can it send a message to one computer from a remote computer?
Did anybody get a NullReferenceException for "int received = socket.EndReceive(AR);" when putting in a request? It gave an error and shut down the server.
I tried this code, and it works...
but somehow. the server stops listening and i got this.
"The thread '' (0x1768) has exited with code 0 (0x0)."
Any helps?
I have a doubt, running this with many clients, using the same static buffer won't make the requests get all mixed?
Hi, Why you didn't develop you server in WCF fullduplex service?
Hi,Dude! Can I create a class based on your method? I asking, because you use static fields...
If you want to get rid of the error that occurs when the client gets closed you need to use a try catch around where you get the exception.
Jesus Christ Ye, gotta catch them all
Its probably not a good idea to try to predict where threads are spawned in Async methods. Just know whether you on a UI thread or not (print out your current thread IDs or something to see). BTW this vid is not meant to explain the behavior of anything, it was just to present a simple design pattern for multiple clients.
I need to construct a server which can receive/store the information in a "friends list" from a client for a chat program. Do you have any suggestions?
Nice tutorial. How can I safely close a socket from client side? Cause' when a client exit the server crash and if not crash (the server not crash every time) and I restart the client server not answer the requests.
all you have to do is use a
try
{
Put the procedure of code that errors it will fix when the client disconnects
}
catch(SocketException)
{
Console.WriteLine("Client Disconnected")
}
Does anybody know how to use this to connect two computers that aren't connected to the same router? (IE, in the same house.) I've never done any network programming or socket programming before.
you need the IP's then the port number
Try put IPAddress.Parse then pass the IP string instead of IPAddress.LoopBack
hey if the client sends a msg end then the server closes that particular socket. but if i close my client console window then my server crashes. can u suggest how to resolve if the client closes the console window or stops running its program then the server must still remain on .
thanks :)
Hi sir, I have two stepper motors connected to my PC using Ethernet cable, is your code able to realize the communication between PC and stepper motor? for example I could send command from clientSide and get response from server side? thank you
I have no way of determining this. Assuming you are connecting to a microboard with compact .net framwork, and all of the references can be resolved, then the code will run fine. Other than that, you should check the CLS compliance of code before installing it on a microboard.
very good job, i used this in my study
when a clients leaves the server crashes. Have i missed something ?
could you please send me the code of these solutions? i can't find them in your attached link. thanks a lot
How would I send the data to multiple clients?
How would you send data to all clients on a list of sockets?
standinonstilts for each (Socket sock in _clientSockets) {
sock.write/beginwrite
}
_clientSockets is the list.
Something like that ^^
How to detect now if a client disconnects properly?! I could send a 'left' message but if i kill the process of the client for example in task manager... how to let the server detect the disconnect of the client
try a simple try-catch on the connection, that should do it.
thank you very much. Really nice explanation
You mean the first letter? Because if I did that it would be akward considering all methods in the framework use PascalCase, plus 97% of 3rd party C# methods.
I have a problem, i open 1 port at My Router, I sent to my friend IP Router and this Port.
My friend can chat with me by using Socket Chat Application, I also chat with myselft by using this.
But 1 program like as Skype or web as facebook not only don't need open a port, but also message is sent. I don't know how I do it?
Hope you give me more inforamation usefully, thanks
Everything you need to know is on this SO post or linked in this SO post regarding Skype's methodologies:
stackoverflow.com/questions/1539339/how-does-skype-work-without-port-forwarding
You can also create dedicated servers and relay everything through them (clients don't need to port forward, only the servers).
Nice video. I want to create a server that send commands to 50 electronics boards, and receive information from that boards. All boards have a micro-controller with Ethernet integrated. Could you show me how I can communicate with this boards?
Are the callbacks for send and receive for receiving and sending from one of the clients or for the server?
Oh, already understand, I don't need any help i think!! Keep up the good work bro!
I get a nullreferenceexception when I do the time command
can you suggest a good book that is up to date?
as I can make one client message is sent to the server and the server will send that message to the client 2 ? thanks , PS: I've been with your video from multiple clients, but I need him as a server that can transmit the message from the client 1 to client 2
+Carlos Lorenzo You will have to send the data to the server then have the server relay it to the other client.
That's the almost exactly the same sentence xD! Can you explain it a little bit better, i need something for that to!
How to make that server remote?
I think using the Socket class would be the best. Theres abstractions like TcpClient and TcpListener that don't seem to make anything easier. I cant tell you if it would be appropriate to adapt the sample. The sample wont be able to retrieve large amounts of data. As well its better just to put all of this stuff in a class library if it were any more complex than this.
if the client lose the connection with the server how can I reconnect to there. Because I tried to turn back the to the loopback(); but it is not connecting back.
have you got answer for your question i need the same answer for the same
I can help with specific things for sure, but if your boards do not run .NET, then I would have little idea how to process the request.
There's an access violation exception when the server sends the time to the second (or third or fourth etc.) clients. The first client that connects works perfectly fine though. Also I did not modify any of the downloaded files.
That totally sounds like a firewall thing.
Normally people use PascalCase for methods but camelCase for variables and such.
hey ,
if i disconnect one of the clients then the server also shuts. how to resolve that ?
I know exactly what you mean, but I left them things out for the sake of the concept
hi I got this exception
The IAsyncResult object was not returned from the corresponding asynchronous method on this class.
and it is under the
private static void AcceptCallback(IAsyncResult result)
on the line
Socket socket = ServerSocket.EndAccept(aresult);
please take look at this link
stackoverflow.com/questions/31139784/the-iasyncresult-object-was-not-returned-from-the-corresponding-asynchronous-met
I could find the problem.
thanks
to make this work through an external ip. The external ip needs to be static and the port you used needs to be port forwarded. if the ip is not static then whenever your network changes you will need to change the client ip to your new ip
also when setting up the connection to the server instead of using (IPAddress.Any , "porthere") you would use (IPAddress.Parse(IPHere), "Port here")
ScriptSpyOfficial Hmm, this doesn't seem to work. Do you mean to use an ip address from www.whatsmyip.org/ ? In order to have a static IP, I am pretty sure you need to own that IP (through a website). I may be wrong about that however.
How can i recieve data from a client and send it to another client so that client can do something with it?
receive*