
31/10/2008, 20:22
|
| | Fecha de Ingreso: mayo-2008
Mensajes: 4
Antigüedad: 16 años, 11 meses Puntos: 0 | |
Ayuda con sockets Ola recien comienzo en c# y estoy intentando una conexion a mi server de cod4 cosa que en pyhon va de maravilla. Se alguien me explicara que es lo que hago mal:
python funcional
Código:
import socket
from time import sleep
def socketconnect(cmd):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(5)
s.connect(("127.0.0.1", 28960))
packet = '\xFF\xFF\xFF\xFFrcon "%s" %s\n' %("123456", cmd)
while len(packet) > 0:
c = s.send(packet)
packet = packet[c:]
sleep(5)
message = s.recv(2048)
s.close()
print message
socketconnect("status")
c# sin respuesta
Código:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IPAddress host = IPAddress.Parse("127.0.0.1");
IPEndPoint hostep = new IPEndPoint(host, 28960);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.Connect(hostep);
string sentence = String.Format("\xFF\xFF\xFF\xFFrcon {0} {0}\n", "123456", "status");
sock.Send(Encoding.ASCII.GetBytes(sentence));
sock.Close();
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}
|