Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 726323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:26:19+00:00 2026-05-14T06:26:19+00:00

Here is my code Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); sck.Bind(new IPEndPoint(IPAddress.Any, 0));

  • 0

Here is my code

Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sck.Bind(new IPEndPoint(IPAddress.Any, 0));

// Broadcast to find server
string msg = "Imlookingforaserver:" + udp_listen_port;
byte[] sendBytes4 = Encoding.ASCII.GetBytes(msg);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("255.255.255.255"), server_port);
sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
sck.SendTo(sendBytes4, groupEP);

//Wait response from server
Socket sck2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sck2.Bind(new IPEndPoint(IPAddress.Any, udp_listen_port));
byte[] buffer = new byte[128];
EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, udp_listen_port);
sck2.ReceiveFrom(buffer, ref remoteEndPoint); //<<< I never pass this line

I use above code to try find a server. First I broadcast a message and then I wait for a response from the server.

A test I made with the server written in C++ and running in Windows Vista, client written in C# and run on the same machine with server.

Problem is: The server can receive message which client broadcast, but client can not receive anything from server.

I try to write a client with C++ and it work like a charm, I think my problem is in C# client.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:26:20+00:00Added an answer on May 14, 2026 at 6:26 am

    I would start listening on that port before you broadcast. You’re using UDP which is connectionless so you could be missing your packet.

    Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    sck.Bind(new IPEndPoint(IPAddress.Any, 0));
    //Wait response from server
    Socket sck2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    sck2.Bind(new IPEndPoint(IPAddress.Any, udp_listen_port));
    byte[] buffer = new byte[128];
    EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, udp_listen_port);
    
    // Broadcast to find server
    string msg = "Imlookingforaserver:" + udp_listen_port;
    byte[] sendBytes4 = Encoding.ASCII.GetBytes(msg);
    IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("255.255.255.255"), server_port);
    sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
    sck.SendTo(sendBytes4, groupEP);
    
    
    sck2.ReceiveFrom(buffer, ref remoteEndPoint);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: try { mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint
I have this code here: var myRequest = new httpReq.myRequest(buffer,socket); if(!myRequest.hasSucceded()){ //return error return;
I have a problem here with this code. I'm opening a socket, then listening
I make a java socket server and c socket client, here are the code
Here is my code using socket.io as WebSocket and backend with pub/sub redis. var
folks, here ma code : #include <glib.h> #include <gio/gio.h> // gio channel #include <sys/socket.h>
I've got this bit of code here: local http = require(socket.http) I know it's
here is my code : import socket import sys import re import base64 import
I am doing a simple communication between sockets and here is my C++ code
The script is on jsfiddle here : CODE What it does at the moment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.