Could someone help me modify this code to C# for wp7,am new to sockets and language bindings, the server is in C. it attached in a zipped file, thanks in advance

Dani AI

Generated

Thread started by asked for a C# port of a C socket server for Windows Phone 7. As noted, the C# forum often has deeper examples; 's comment about not rewriting the server is relevant — porting the client is usually faster and safer than reimplementing a production server.

Important platform and protocol notes: Windows Phone socket support requires the OS/SDK that exposes System.Net.Sockets (Windows Phone OS 7.1/Mango and later). Socket operations must be asynchronous on the phone UI thread. Confirm whether the C server uses TCP or UDP, any binary struct layouts, message framing (length-prefix vs delimiter), and endianness. C struct padding and compiler-dependent packing will not map automatically to C#; serializing fields explicitly (byte arrays, BitConverter, IPAddress.NetworkToHostOrder) is the reliable approach. If the server uses raw IP headers or privileged operations, the phone platform will not support that.

Minimal pattern (Begin/End async) for a TCP client on WP7:

using System.Net;
using System.Net.Sockets;
using System.Text;

var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.BeginConnect(new IPEndPoint(IPAddress.Parse("192.168.1.100"), 12345), ar =>
{
    try
    {
        sock.EndConnect(ar);
        var buf = new byte[1024];
        sock.BeginReceive(buf, 0, buf.Length, SocketFlags.None, iar =>
        {
            int r = sock.EndReceive(iar);
            // process buf[0..r]
        }, null);
    }
    catch { /* handle errors */ }
}, null);

Quick testing tips: run a simple TCP server on a PC, open the firewall port, and use the PC LAN IP when using the WP7 emulator (127.0.0.1 on the emulator will not reach the host). Log raw bytes (hex) and verify handshakes with Wireshark or netcat to match the C server protocol exactly.

Recommended Answers

All 5 Replies

Try posting this in the C# forum

here is the link

http://www.daniweb.com/software-development/csharp/61

Hope you get your problem solved. Do not marked this threads as solved since i did not contribute much help

Can you please tell me what browser I use as default and how do I change it?I have an lg ally mobile smart phone powered by android and am being told different answers. I want to change to a browser that supports flash.

Start a new thread please and please do not hijack old threads. Thanks. After you have created a new thread in this forum, i will reply to it.

LOL! Why would someone go out of their way to re-write a server for a random person with 4 posts? I mean, would you do this for someone? I sure hope not...

I doubt the original poster went to the forum i posted and create a new thread. Hi skatamatic, nice to see you. Welcome back to daniweb! Gosh, you join daniweb earlier than me by four years, that makes you my senior.:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.