✅ Help with sockets c#
how would i go by showing a message to every client connected to a server ?
96 Replies
Ehmmm.. Check out SignalR library
loop over your connections and send each of them a message?
kind of an abstract question that depends on how your server is implemented
im not using any library
just sockets
okay but how do i loop over them when i dont have them stored ?
is there a way to store them ?
ill show you my server class
you have to be storing them somewhere already
my main issue is how do i get reference from my textbox in the client form
you might need to add a list of them so you can access all the active connections easily
im using winform btw
unfortunate
(not for this problem, just in general)
yeah even if i access that.. my main issue is how to get reference to a chat text box in another form
here is my server code
client code
(this is not final i just want to figure out this chat box thing)
client home page which also looks like this
server home page
just a start that starts the server
what i have rn is whenever a client sends a message it shows a pop up with client(2) has sent a message: <message here>
the client number increases with the number of client threads
soon i want to add a client name etc but now i just wanna figure out a way to show the message instead of a popup. it shows in every other client's chat box
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i se
ill check it out
people said if u really wanna learn ab sockets and stuff u need to use the real deal
not libraries
signalr is web sockets
i see
and normal sockets are ?
they're sockets
can i use signalr with winform
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
you can, but it's not plain sockets
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
soo as a service ?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
yes
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
can i still achieve what i want with normal sockets ?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
yeah 😂
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
will i even benifit anything from doing this
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
.
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i don't understand why you're suggesting websockets
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
this looks like a practice application to work with basic networking
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
spinning up an entire web application to use websockets instead seems kind of out of scope of the project
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
the goal is both
learn and create a chat app
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
but i found 0 good source for learning sockets
so i just dived in lmao
and i have had so many bugs
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
do you have good sources atleast ?
youtube videos ?
i'd be thankful
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
ill check that out
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i am not
thats why ive been avoiding it
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
yeah i tried using async
it told me no void allowed
so i just removed tha async part lmao
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i actually tried it and it told me i cant use void return type with async
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
wait wdym ?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
yeah
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
Opinion: first article looks better as an introduction than the devblog one, but but should still be read in that order
https://github.com/tkp1n/ndportmann.com/blob/master/posts/2019-01-03--system-threading-channels/index.md
https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels
https://www.stevejgordon.co.uk/an-introduction-to-system-threading-channels
Video:
https://docs.microsoft.com/en-us/shows/on-net/working-with-channels-in-net
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
alright ill check it out
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
yeah i take the message as string from the textbox and i send it as bytes
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
so it gets encoded at the other end
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i actually dont i have it set at 1024 for now
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
the messages will be cut and sent in pieces
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
it already happened
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
ohh
okay thats smart
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i didnt even know that existed
alright
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i see
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i see i see
alrighttt
one last question
in this server.listen
does it make the main thread wait until it receives any connection ?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
or does it keep on going normally
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
ill just add the message length as a prefix 😂
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
then i can just read the prefix and double it
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i see
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
that is alot of info that i dont understand yet
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
soo can i just set it as that ?
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View
i see i see
Unknown User•9mo ago
Message Not Public
Sign In & Join Server To View